elasticsearch 在ElasticSearch 5.6.3中获取嵌套文档的聚合会导致Lucene异常
我对
elasticsearch 在ElasticSearch 5.6.3中获取嵌套文档的聚合会导致Lucene异常,
elasticsearch,lucene,aggregation,
elasticsearch,Lucene,Aggregation,我对ElasticSearch 5.6.3上的嵌套文档聚合有问题 我的查询的结构如下所示: query aggs |_filter |_nested |_term |_top-hits 如果我尝试在非嵌套字段上进行聚合(当然删除了嵌套的agg),那么一切都会按预期进行。但由于现在的结构,我收到了Lucene的一个例外: 子查询不能与具有父筛选器的相同文档匹配。将它们组合为必需子句(+)以查找问题文档。docId=2147483647,class
ElasticSearch 5.6.3
上的嵌套文档聚合有问题
我的查询的结构如下所示:
query
aggs
|_filter
|_nested
|_term
|_top-hits
如果我尝试在非嵌套字段上进行聚合(当然删除了嵌套的agg),那么一切都会按预期进行。但由于现在的结构,我收到了Lucene的一个例外:
子查询不能与具有父筛选器的相同文档匹配。将它们组合为必需子句(+)以查找问题文档。docId=2147483647,class org.apache.lucene.search.ConstantScoreScoreScorer
ElasticSearch2.4.6
不会触发此异常
我试图以不同的方式构建聚合,但我无法想出一个有效的组合并提供想要的结果
这是映射的外观:
"recording": {
"dynamic": "strict",
"_all" : {
"enabled" : false
},
"properties": {
"id": {
"type": "integer"
},
"soloists": {
"properties": {
"type": "nested",
"person": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string",
"index": "not_analyzed"
}
}
}
},
"work": {
"id": {
"type": integer
},
"title": {
"type": "string",
"index": "not_analyzed"
}
}
}
以及查询本身:
{
"query": {},
"aggs": {
"my_top_results": {
"global": {},
"aggs": {
"my_filter_agg": {
"filter": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"nested": {
"path": "soloists",
"query": {
"bool": {
"must": {
"match": {
"soloists.person.id": 77957
}
}
}
}
}
}
]
}
}
]
}
},
"aggs": {
"my_nested_agg": {
"nested": {
"path": "soloists"
},
"aggs": {
"my_terms_agg": {
"term": {
"field": "soloists.person.id",
"size": 10
}
"aggs": {
"my_top_hits_agg": {
"size": 1,
"_source": {
"include": [
"soloists.person.id",
"soloists.person.name"
]
}
}
}
}
}
}
}
}
}
}
}
}
任何帮助都将不胜感激
我在寻找解决方案时偶然发现了一些链接:
HOST=10.225.0.2:9200
curl -XPUT "http://$HOST/an_index"
curl -XPUT "http://$HOST/an_index/recording/_mapping" -H 'Content-Type: application/json' -d'
{
"dynamic": "strict",
"_all": {
"enabled": false
},
"properties": {
"id": {
"type": "integer"
},
"soloists": {
"type": "nested",
"properties": {
"person": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
},
"work": {
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}'
curl -XPOST "http://$HOST/an_index/recording/1" -H 'Content-Type: application/json' -d'
{
"id": 0,
"soloists": [
{
"person": {
"id": 77957,
"name": "John doe"
}
},
{
"person": {
"id": 1,
"name": "Jane smith"
}
}
],
"work": {
"id": 0,
"title": "Test"
}
}'
curl -XGET "http://$HOST/an_index/recording/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"my_top_results": {
"global": {},
"aggs": {
"my_filter_agg": {
"filter": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"nested": {
"path": "soloists",
"query": {
"bool": {
"must": {
"match": {
"soloists.person.id": 77957
}
}
}
}
}
}
]
}
}
]
}
},
"aggs": {
"my_nested_agg": {
"nested": {
"path": "soloists"
},
"aggs": {
"my_terms_agg": {
"terms": {
"field": "soloists.person.id",
"size": 10
},
"aggs": {
"my_top_hits_agg": {
"top_hits": {
"size": 1,
"_source": {
"include": [
"soloists.person.id",
"soloists.person.name"
]
}
}
}
}
}
}
}
}
}
}
}
}
}'
如果这些查询有效,但应用到索引时无效,请使用
curl-XGET“http://$HOST/your_index_name”
的输出更新您的问题,以便我们检查索引的精确设置和映射?这种错误可能是由同一索引上的类型之间的冲突引起的。我会相应地更新我的答案 嘿,克劳迪乌,第一件事是my\u top\u hits\u agg
不在正确的位置,它应该位于my\u terms\u agg
聚合中,top\u hits
关键字缺失,对吗?我很惊讶这个查询居然会运行。嘿@Val!这样一种偶然的会面方式。你完全正确-这是我的复制粘贴错误。刚刚修复了查询,但问题仍然存在……的确;-)如果您将过滤器简化为最少需要的过滤器,即仅嵌套过滤器(删除bool/must+bool/shoul部分),会发生什么情况?任何输入Claudiu?很抱歉延迟响应@val,这是一些家族企业的侧重点。我最终以一种完全不同的方式解决了这个问题,没有使用聚合。无论如何,圣诞快乐!谢谢@Pandawan!我最终设法以一种完全不同的方式解决了查询,这种方式符合我们的业务逻辑。无论如何,感谢您的回答,并对延迟回复表示抱歉。