elasticsearch - ElasticSearch嵌套_count查询获取 “request does not support [filter]”

标签 elasticsearch

使用_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/

相关文章:

spring-boot - nodeBuilder() 已被 Elasticsearch 删除,但 spring-data-elasticsearch 文档仍然包含使用 nodeBuilder() 的配置

java - ElasticSearch SpringBoot+Spring Data : java. lang.IllegalStateException:在接口(interface)上找不到合适的构造函数

elasticsearch - elasticsearch生成的ids的长度和字符是多少?

java - unix/linux 无法解压缩用于 Elasticsearch 的文件

elasticsearch - 带空格的Elasticsearch术语

elasticsearch - 将预先标记的文本插入Elasticsearch

java - Elastic Search 过滤了具有未映射字段的别名

java - 返回带有对象列表的 ResponseEntity

elasticsearch - 什么是 Elasticsearch 索引?

elasticsearch - 如何在嵌入式ElasticSearch中记录所有查询?