无法在弹性搜索中检索嵌套对象

问题描述

这里是一个 ELK 菜鸟,最后一分钟让 ELK 任务交给我。

我们在车辆索引中添加一个名为 prospects 的额外数据,以便用户可以搜索它。我可以将 prospects 添加到索引中,现在我无法在车辆索引中获取嵌套的 prospects obj。我正在使用 Elastic Search & Kibana v6.8.11 和 elastic-search-rails gem 并检查了嵌套对象的文档。根据文档,我的搜索方法看起来是正确的。想请专家指出这里有什么问题,如果您需要更多信息,请告诉我。

这里是假设索引 obj -

      {
        "_index" : "vehicles","_type" : "_doc","_id" : "3MZBxxxxxxx","_score" : 0.0,"_source" : {
          "vin" : "3MZBxxxxxxx","make" : "mazda","model" : "mazda3","color" : "unkNown","year" : 2018,"vehicle" : "2018 mazda mazda3","trim" : "grand touring","estimated_mileage" : null,"dealership" : [
            209
          ],"current_owner_group_id" : null,"current_owner_customer_id" : null,"last_service_date" : null,"last_service_revenue" : null,"purchase_type" : [ ],"in_service_date" : null,"deal_headers" : [ ],"services" : [ ],"customers" : [ ],"salesmen" : null,"service_appointments" : [ ],"prospects" : [
            {
              "first_name" : "Kammy","last_name" : "Maytag","name" : "Kammy Maytag","company_name" : null,"emails" : [ ],"phone_numbers" : [ ],"address" : "31119 field","city" : "helen","state" : "keller","zip" : "81411","within_dealership_aoi_region" : true,"dealership_ids" : [
                209
              ],"dealership_dppa_protected_ids" : [
                209
              ],"registration_id" : 12344,"id" : 1054,"prospect_source_id" : "12344","type" : "Prospect"
            }
          ]
        }
      }
    ]
  }
}

这是我尝试获取它的方式 -

 GET /vehicles/_search
{
  "query": {
    "bool": {
      "must": { "match_all": {} },"filter": [
        { "term": { "dealership": "209" } },{
          "nested": {
            "path": "prospects","query": {
              "bool": {
                "must": [
                  { "term": { "prospects.first_name": "Kammy" } },{ "term": { "prospects.dealership": "209" } },{ "term": { "prospects.type": "Prospect" } }
                ]
              }
            }
          }
        },{ "bool": { "must_not": { "term": { "purchase_type": "Wholesale" } } } }
      ]
    }
  },"sort": [{ "_doc": { "order": "asc" } }]
}

解决方法

我发现嵌套查询有两个问题:

  1. 您正在查询 prospects.dealership,但示例文档仅显示 prospects.dealership_ids。将查询更改为目标 prospects.dealership_ids
  2. 更重要的是,您正在对 termprospects.first_name 使用 prospects.type 查询。我假设您的索引映射没有将它们定义为 keywords,这意味着它们很可能是小写的(出于 explained here 的原因),但 term 正在寻找完全匹配。
    • 选项 1:使用 match 而不是 term
    • 选项 2:更改 prospects.first_nameprospects.first_name.keyword 并对 .type 执行相同操作。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...