按_source

时间:2019-01-18 10:46:26

标签: elasticsearch elasticsearch-aggregation

elasticsearch中有一个索引,其中包含如下所示的文档:

 "hits": [
        {
            "_index": "my-index2",
            "_type": "my-type",
            "_id": "1",
            "_score": 1,
            "_source": {
                "entities": {
                    "persons": [
                        "Kobe Bryant",
                        "Michael Jordan"
                    ],
                    "dates": [
                        "Yesterday"
                    ],
                    "locations": [
                        "Munich",
                        "New York"
                    ]
                },
                "my_field": "Kobe Bryant was one of the best basketball players of all times. Not even Michael Jordan has ever scored 81 points in one game. Munich is really an awesome city, but New York is as well. Yesterday has been the hottest day of the year."
            }
        }

是否可以使用聚合函数按entities对象中的字段进行聚合?我试过了,但是没用

{
    "aggs" : {
        "avg_date" : {
            "avg" : {
                "script" : {
                    "source" : "doc.entities.dates"
                }
            }
        }
    }
}

该错误表明我的索引没有entities字段。

编辑:带有以下术语汇总查询:

{
    "aggs" : {
        "dates" : {
            "terms" : { "field" : "entities.dates" }
        }
    }
}

我说一个错误

  

默认情况下,在文本字段上禁用字段数据。在[entities.dates]上设置fielddata = true,以通过反转取反的索引将字段数据加载到内存中。

我可以像错误信息一样设置fielddata = true,但是我应该警告文档,因为它占用了大量的堆空间。还有其他方法可以执行此查询吗?

编辑2:通过将entities中的所有字段设置为索引中的关键字来解决此问题。

0 个答案:

没有答案