elasticsearch 匹配查询 returns 嵌套字段的空结果

elasticsearch match query returns empty results for nested fields

我正在关注这个link 我的索引 test_products 包含以下内容 mapping:

{
"settings": {
    "number_of_shards": 1
},
"mappings": {
    "dynamic_templates": [
        {
            "search_result_data": {
                "mapping": {
                    "type": "keyword"
                },
                "path_match": "search_result_data.*"
            }
        }
        ],
    "properties": {
        "search_data": {
            "type": "nested",
            "properties": {
                "full_text": {
                    "type": "text"
                },
                "string_facet": {
                    "type": "nested",
                    "properties": {
                        "facet-name": {
                            "type": "keyword"
                        },
                        "facet-value": {
                            "type": "keyword"
                        }
                    }
                }
            }
        }
    }
}
}

并插入了以下格式的文档:

    {
  "search_result_data": {
    "sku": "wheel-6075-90092",
    "gtin": null,
    "name": "Matte Black Wheel Fuel Ripper",
    "preview_image": "abc.jg",    
    "url": "9836817354546538796",
    "brand": "Fuel Off-Road"
  },
  "search_data": 
    {
      "full_text": "Matte Black Wheel Fuel Ripper",
      "string_facet": [
        {
          "facet-name": "category",
          "facet-value": "Motor Vehicle Rims & Wheels"
        },
        {
          "facet-name": "brand",
          "facet-value": "Fuel Off-Road"
        }
      ]
    }    
}

和其他一些文件..

我正在尝试使用以下查询对索引进行全文搜索:

{
    "query": {
        "match": {
            "search_data.full_text": "Black"
        }
    }
}

尽管该字段包含术语 Black

,但此查询的结果为空

由于您的 search_data 字段是 nested,您还需要使用 nested query

{
  "query": {
    "nested": {
      "path": "search_data",
      "query": {
        "match": {
          "search_data.full_text": "Black"
        }
      }
    }
  }
}