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

Unable to retrieve nested object within Elastic Search

这里是 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. 更重要的是,您正在 prospects.first_nameprospects.type 上使用 term 查询。我假设您的索引映射没有将它们定义为 keywords which means that they were most likely lowercased (for reasons ) 但 term 正在寻找完全匹配。
    • 选项 1:使用 match 而不是 term
    • 选项 2:更改 prospects.first_nameprospects.first_name.keyword 并对 .type.
    • 执行相同操作