名为id的嵌套字段中的术语过滤器无法正常工作 [英] Term Filter on a nested field called id does not work as expected
问题描述
提前感谢Hannes
Mapping(reduced):
类型:
学院:
映射:
id:〜
premium:{type:boolean}
boost:{type :boolean}
课程:
映射:
_all:{analyzer:text}
id:{type:string,analyzer :term}
name:{type:string,analyzer:text}
types:{type:string,analyzer
学院:
类型:对象
属性:
id:{type:string,analyzer:term}
name:{type:string,analyzer:text}
_parent:
类型:学院
查询:
GET _search
{
query {
function_score:{
query:{
has_child:{
type:course,
query b $ b已过滤:{
查询:{
match_all:{}
},
过滤器:{
bool {
must:[
{
terms:{
college.id:[
371
]
}
}
]
}
}
}
}
}
}
}
},
aggs {
children:{
children:{
type:course
},
aggs:{
过滤:{
过滤器:{
查询:{
过滤:{
查询:{
match_all:{}
},
过滤器:{
bool:{
必须:[
{
条款:{
college.id:[
371
]
}
}
]
}
}
}
}
},
aggs:{
abschluss:{
terms:{
field:degree,
size:0
},
aggs
unique:{
cardinality:{
field:_parent,
precision_threshold:500
}
}
},
coursecount:{
terms:{
field:_parent,
size:0
}
}
}
}
}
}
},
from:0,
大小:20
}
结果: p>
{
taken:2,
timed_out:false,
_shards:{
total:1,
success:1,
failed:0
,
hits:{
total:1,
max_score:1,
hits:[
{
_ $$$$$$$$$$$$$$
id:371,
premium:true,
boost:null
}
}
]
},
aggregations:{
children:{
doc_count:15,
filtered:{
doc_count:0,
coursecount:{
doc_count_error_upper_bound:0,
sum_other_doc_count:0,
buckets:[]
},
abschluss :{
doc_count_error_upper_bound:0,
sum_other_doc_count:0,
buckets:[]
}
}
}
}
}
我重新命名了这个问题,自己回答,以便别人找到它。似乎一个名为id的字段是预留/预配置的,因此它不能在术语过滤器中使用。将该字段重命名为其他解决方案的问题。
过滤器:{
bool:{
must:[
{
terms:{
college.myId:[
371
]
}
}
]
}
I have a very strange problem/bug that I dont understand. I have a child (course) - parent (college) relationship. I query for courses that belong to a certain college, which works fine. Due to the concept of my application, I also need to query for colleges that have courses that belong to a certain college and than aggregate over the result. I am using this concept for different aggregations and everything works fine except for this one case which does not make sense to me. Please note: I have two types - college and course - and the type course has also a nested object called college. This is nedded to be able to to certain aggregations as parent-aggregations are not supported in ES. This concept works very well for me and I don't think it has anything to do with the mentioned problem/bug.
Thanks in advance, Hannes
Mapping (reduced):
types:
college:
mappings:
id: ~
premium: { "type": "boolean" }
boost: { "type": "boolean" }
course:
mappings:
_all: { "analyzer": "text" }
id: { "type": "string", "analyzer": "term" }
name: { "type": "string", "analyzer": "text" }
types: { "type": "string", "analyzer": "term" }
college:
type: "object"
properties:
id: { "type": "string", "analyzer": "term" }
name: { "type": "string", "analyzer": "text" }
_parent:
type: "college"
Query:
GET _search
{
"query": {
"function_score": {
"query": {
"has_child": {
"type": "course",
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"terms": {
"college.id": [
"371"
]
}
}
]
}
}
}
}
}
}
}
},
"aggs": {
"children": {
"children": {
"type": "course"
},
"aggs": {
"filtered": {
"filter": {
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"terms": {
"college.id": [
"371"
]
}
}
]
}
}
}
}
},
"aggs": {
"abschluss": {
"terms": {
"field": "degree",
"size": 0
},
"aggs": {
"unique": {
"cardinality": {
"field": "_parent",
"precision_threshold": 500
}
}
}
},
"coursecount": {
"terms": {
"field": "_parent",
"size": 0
}
}
}
}
}
}
},
"from": 0,
"size": 20
}
Result:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "studiengaenge_dev",
"_type": "college",
"_id": "371",
"_score": 1,
"_source": {
"id": "371",
"premium": true,
"boost": null
}
}
]
},
"aggregations": {
"children": {
"doc_count": 15,
"filtered": {
"doc_count": 0,
"coursecount": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
},
"abschluss": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
}
}
}
I renamed the question and answer it myself so that other people can find it. It seems that a field called "id" is kind of reserved/preconfigured, so that it can not be used in term filters. Renaming the field to something else solved my problem.
"filter": {
"bool": {
"must": [
{
"terms": {
"college.myId": [
"371"
]
}
}
]
}
这篇关于名为id的嵌套字段中的术语过滤器无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!