ElasticSearch嵌套查询

yb3bgrhw  于 2023-02-18  发布在  ElasticSearch
关注(0)|答案(2)|浏览(127)

我有一个包含一些嵌套信息的索引,现在正纠结于如何进行查询。
下面的索引代表一辆车,这辆车属于2汽车。

{
    "_index": "items_production_20180411115923024",
    "_type": "item",
    "_id": "1232",
    "_score": 21.715849,
    "_source": {
      "description": "CUBO RODA TRASEIRA VW:GOL, VOYAGE G5/G6 09> C/ABS",
      "observation": null,
      "brand_id": "1 ",
      "product_line_id": "13",
      "line_id": "1",
      "line": "Rolamentos",
      "segment_id": "21",
      "segment": "cubo de roda",
      "application_features": [
        "4 furos"
      ],
      "original_codes": [
        " 5u0 501 611 "
      ],
      "original_brands": [
        "volkswagen"
      ],
      "vehicles": [
        {
          "id": "285",
          "brand": "volkswagen",
          "name": "golf",
          "years": [
            "2009",
            "2010",
            "2011",
            "2012",
            "2013",
            "2014",
            "2015",
            "2016",
            "2017",
            "2018"
          ]
        },
        {
          "id": "345",
          "brand": "volkswagen",
          "name": "jetta",
          "years": [
            "2015",
            "2016",
            "2017",
            "2018"
          ]
        }
      ]
    }
  }

我必须使查询匹配到一个单一的结果时,搜索车型和年份的汽车.即:

GET items_production_20180411115923024/_search
   {
     "query":{
    "bool":{
      "must":{
        "multi_match":{
          "query":"golf 2010",
          "type":"cross_fields",
          "operator":"and",
          "fields":[
            "vehicles.name^8",
            "vehicles.years^8"
          ]
        }
      }
    }
  },
  "size":10,"from":0
}

我必须归还2010年高尔夫球年的所有文件,但我的回答是没有?
我做错了什么?我怎么能做这个查询?

5w9g7ksd

5w9g7ksd1#

我发现您的查询中有拼写错误。请将vehicle_names^8替换为vehicles.name^8

yizd12fk

yizd12fk2#

车辆.年份是一个分析字段吗?如果不是,它将不能与术语“高尔夫2010”匹配。
您可以在Map中使用copy_to,从一个字段中的name和year中获取术语,然后可以针对该术语执行简单的查询。

相关问题