使用_search
运行查询时,我的查询工作正常,但使用_count
运行查询失败。有人可以告诉我为什么吗?我宁愿不必为了获得计数而运行完整的查询。
这是查询。
{
"filter": {
"nested": {
"filter": {
"bool": {
"must": [
{
"term": {
"user_id": 5
}
}
]
}
},
"path": "participants"
}
}
}
这是失败的:
{
"count": 0,
"_shards": {
"total": 5,
"successful": 0,
"failed": 5,
"failures": [
{
"index": "messages_20150428_000025",
"shard": 0,
"reason": "BroadcastShardOperationFailedException[[messages_20150428_000025][0] ]; nested: QueryParsingException[[messages_20150428_000025] request does not support [filter]]; "
},
{
"index": "messages_20150428_000025",
"shard": 1,
"reason": "BroadcastShardOperationFailedException[[messages_20150428_000025][1] ]; nested: QueryParsingException[[messages_20150428_000025] request does not support [filter]]; "
},
{
"index": "messages_20150428_000025",
"shard": 2,
"reason": "BroadcastShardOperationFailedException[[messages_20150428_000025][2] ]; nested: QueryParsingException[[messages_20150428_000025] request does not support [filter]]; "
},
{
"index": "messages_20150428_000025",
"shard": 3,
"reason": "BroadcastShardOperationFailedException[[messages_20150428_000025][3] ]; nested: QueryParsingException[[messages_20150428_000025] request does not support [filter]]; "
},
{
"index": "messages_20150428_000025",
"shard": 4,
"reason": "BroadcastShardOperationFailedException[[messages_20150428_000025][4] ]; nested: QueryParsingException[[messages_20150428_000025] request does not support [filter]]; "
}
]
}
}
鉴于此,此嵌套字段的映射:
"participants": {
"type": "nested",
"properties": {
"archived": {
"type": "boolean"
},
"has_unread": {
"type": "boolean"
},
"name": {
"type": "string"
},
"pk": {
"type": "long"
},
"user_id": {
"type": "long"
}
}
},
和这些数据(仅适用于此嵌套字段):
"participants": [
{
"archived": false,
"user_id": 5,
"name": "Person A",
"has_unread": false,
"pk": 1
},
{
"archived": false,
"user_id": 7,
"name": "Person B",
"has_unread": false,
"pk": 2
}
],
最佳答案
根据documentation 的计数只能接受查询,因此您需要将其重写为
{
"query": {
"filtered": {
"filter": {
"nested": {
"filter": {
"bool": {
"must": [
{
"term": {
"user_id": 5
}
}
]
}
},
"path": "participants"
}
}
}
}
}
关于elasticsearch - ElasticSearch嵌套_count查询获取 “request does not support [filter]”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29976302/