php - 如何在Elasticsearch中使用聚合?我尝试使用以下代码,但显示错误

标签 php codeigniter elasticsearch

我的代码:

$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/

相关文章:

javascript - JSPDF 和 AutoTable 的问题

php - 如何处理Codeigniter中的4xx和5xx错误?

PHP 代码适用于共享主机,但不适用于 Xampp

php - 人们使用 Elasticsearch 做什么?

elasticsearch - 有没有办法在elasticsearch中提高长文档的匹配度

php - 当一个输入被填满时,如何使用ajax获取mysql数据

临时目录中的 phpXXXX.tmp 文件中包含的 PHP 代码

python - Python-将地理数据插入 Elasticsearch 后,如何搜索数据?

php - 如何将表格特定行的特定 Tds 转换为文本框,以便可以编辑它们的值

php - 在 Codeigniter 的依赖选择框中显示数据库中的特定数据