elasticsearch匹配查询为嵌套字段返回空结果

时间:2019-08-14 11:28:01

标签: elasticsearch elasticsearch-aggregation

我正在关注此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,但该查询的结果还是空的。

1 个答案:

答案 0 :(得分:2)

由于您的UIView!字段为search_data,因此您还需要使用nested query

nested
相关问题