多个字段的弹性搜索布尔查询
Elastic Search Bool Query for multiple fields
我有如下索引映射:
要求
|-> tilte
|-> countryCode
|-> isOpen
|-> location
|-> date
我想同时进行 bool 和 geoquery 获取同一个国家和我附近的文档isOpen
我已经尝试了下面的但我总是得到一个空的命中对象。
{ "from" : 5,
"size": 5,
"query": {
"bool" : {
"must" : [
{"match" : {"countryCode": "US"}},
{"match": {"isOpen": true }}
],
"filter" : {
"geo_distance" : {
"distance" : "150km",
"location" : {
"lat" : 1111111111,
"lon" : 3333333333
}
}
}
}
},
"sort": [ { "date" : {"order" : "desc"} } ]
}
回应
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
即使我确定有很多文档与查询匹配,但我无法获取。谁能帮忙?
我将从将 from
值从 5 更改为 0 开始。接下来我将检查索引定义 - 您确定可以按照您使用的方式搜索每个字段吗?你能展示确切的索引定义(映射)并展示来自 Elastic 的示例项目吗?
我有如下索引映射:
要求
|-> tilte
|-> countryCode
|-> isOpen
|-> location
|-> date
我想同时进行 bool 和 geoquery 获取同一个国家和我附近的文档isOpen
我已经尝试了下面的但我总是得到一个空的命中对象。
{ "from" : 5,
"size": 5,
"query": {
"bool" : {
"must" : [
{"match" : {"countryCode": "US"}},
{"match": {"isOpen": true }}
],
"filter" : {
"geo_distance" : {
"distance" : "150km",
"location" : {
"lat" : 1111111111,
"lon" : 3333333333
}
}
}
}
},
"sort": [ { "date" : {"order" : "desc"} } ]
}
回应
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
即使我确定有很多文档与查询匹配,但我无法获取。谁能帮忙?
我将从将 from
值从 5 更改为 0 开始。接下来我将检查索引定义 - 您确定可以按照您使用的方式搜索每个字段吗?你能展示确切的索引定义(映射)并展示来自 Elastic 的示例项目吗?