名为id的嵌套字段上的术语过滤器无法按预期工作

时间:2016-04-12 12:50:59

标签: elasticsearch

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

先谢谢,Hannes

映射(缩小):

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"

查询:

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
}

结果:

{
   "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": []
            }
         }
      }
   }
}

1 个答案:

答案 0 :(得分:0)

我重新命名了问题并自己回答,以便其他人可以找到它。这似乎是一个名为" id"是一种保留/预配置,因此它不能用于术语过滤器。将字段重命名为其他内容可以解决我的问题。

<list elements="elements">
    <div ng-controller="CustomMethodsController">
        <div class="col-xs-6">
            {{result.element_1}}
        </div>
        <div class="col-xs-6">
            {{result.element_2}}
        </div>
    </div>
</list>