此查询返回uuid
子句中带有must_not
的第一条记录。
当删除排序时,带有uuid
的文档不在列表中,但我得到随机结果,我希望它们按位置asc排序(似乎包括)
使用6.0 api版本。
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"location": {
"lat": -33,
"lon": 151
},
"distance": "100km"
}
},
"must_not": {
"term": {
"uuid": "a3330c1a-8a24-4c7f-ad97-16ac5bd73e3f"
}
}
}
},
"sort": [
{
"_geo_distance": {
"location": {
"lat": -33,
"lon": 151
},
"order": "asc",
"unit": "km",
"mode": "min",
"distance_type": "arc"
}
}
],
"size": 10
}
{
"took": 17,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1504,
"max_score": null,
"hits": [
{
"_index": "myindex",
"_type": "mytype",
"_id": "a3330c1a-8a24-4c7f-ad97-16ac5bd73e3f",
"_score": null,
"_source": {
"latitude": -33,
"longitude": 151,
"uuid": "a3330c1a-8a24-4c7f-ad97-16ac5bd73e3f",
"location": [
151,
-33
]
},
"sort": [
0
]
}
]
答案 0 :(得分:0)
您的 uuid 字段是否为文字或关键字?查看Why doesn’t the term query match my document部分。
有两种解决方案:
1)将您的查询更改为:
"must_not": {
"term": {
"uuid.keyword": "a3330c1a-8a24-4c7f-ad97-16ac5bd73e3f"
}
}
或2)将您的uuid字段定义为关键字而不是文字:
PUT myindex
{
"mappings": {
"mytype": {
"properties": {
"uuid": {
"type": "keyword"
}
}
}
}
}