ES查询不出预期结果
ES索引
PUT /goods
{
"mappings": {
"goods": {
"properties": {
"id": {
"type": "keyword"
},
"goods_list": {
"type": "nested",
"include_in_parent": true,
"properties": {
"name": {
"type": "keyword"
},
"price": {
"type": "keyword"
}
}
}
}
}
}
}
ES数据
{
"_source": {
"id": "1",
"goods_list": [
{
"name": "mi1",
"price": "1999"
},
{
"name": "mi2",
"price": "4999"
}
]
},
"_source": {
"id": "2",
"goods_list": [
{
"name": "mi3",
"price": "3999"
},
{
"name": "mi2",
"price": "4999"
}
]
}
}
ES查询语句
GET /goods/_search
{
"query": {
"nested": {
"path": "goods_list",
"query": {
"bool": {
"must": [
{
"match": {
"goods_list.price":
"1999"
}
},
{
"match": {
"goods_list.price":
"4999"
}
}
]
}
}
}
}
}
运行结果及报错内容
通过这个查询语句想匹配到goods_list中包含价格为1999和4999的记录,但是这个查询语句查无结果。
但是把goods_list修改为非nested类型的,就可以查询到结果。
这种用法是否正确? 及其原因?及正确的解决办法?