名为id的嵌套字段中的术语过滤器无法正常工作 [英] Term Filter on a nested field called id does not work as expected

查看:123
本文介绍了名为id的嵌套字段中的术语过滤器无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的问题/ bug,我不明白。我有一个孩子(课程) - 父母(大学)的关系。我查询属于某所大学的课程,工作正常。由于我的申请概念,我还需要查询具有属于某所大学的课程的学院,而不是结果。我使用这个概念不同的聚合,一切都正常,除了这一个对我没有意义的情况。请注意:我有两种类型 - 大学和课程 - 类型课程也有一个称为大学的嵌套对象。由于ES中不支持父集合,因此可以进行某些聚合。这个概念对我来说很好,我不认为它与上述的问题/ bug有任何关系。



提前感谢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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆