我的代码:
$test1 = '{
"query": {
"query_string": {
"query": "*"
}
},
"aggs": {
"AGE": {
"filter": {
"range": {
"age": { }
}
}
}
},
"sort": {
"age": {
"order": "desc"
}
}
}';
$response = $this->elasticsearch->advancedquery("comment", $test1);
数据库名称是默认在类文件中设置的,
("comment", $test1);
'comment'是表名称。这个查询有什么问题吗?
运行查询时,出现以下错误
[root_cause] => Array
(
[0] => Array
(
[type] => illegal_argument_exception
[reason] => Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.
)
)
最佳答案
在5.x版本中,默认情况下在文本字段上禁用FieldData
。如果需要,您需要启用它们。
根据documentation
Fielddata can consume a lot of heap space, especially when loading high cardinality text fields. Once fielddata has been loaded into the heap, it remains there for the lifetime of the segment. Also, loading fielddata is an expensive process which can cause users to experience latency hits. This is why fielddata is disabled by default.
如果要在字段上运行聚合,则需要启用它,例如:
PUT my_index/_mapping/my_type
{
"properties": {
"age": {
"type": "text",
"fielddata": true
}
}
}
希望这可以帮助!!
关于php - 如何在Elasticsearch中使用聚合?我尝试使用以下代码,但显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44753455/