带有脚本doc_values的ElasticSearch聚合

时间:2016-02-27 17:52:21

标签: php elasticsearch aggregation elastica

我有一个字段" location_facet",这是一个带映射的strig

"location_facet": {
                  "type": "string",
                  "index": "not_analyzed",
                  "include_in_all": true
               },

在这个字段中我有location_ids,我想通过查询聚合它们。此外,我想通过聚合成为一些信息,这就是我想要执行脚本的原因,例如我想成为城市的名称,但总会出现错误:

"aggs": {
        "location_radius": {
            "terms": {
                "field": "location_facet",
                "size": 10,
                "script": "doc[\"location_name\"].value"
            }
        }
},


"type": "script_exception",
            "reason": "failed to run inline script [doc[\"location_name\"].value] using lang [groovy]"

我实际上使用Facets实现了这个实现:

$tagFacet = new \Elastica\Facet\Terms("location_radius");
$tagFacet->setField('location_name');
$tagFacet->setAllTerms(true);
$tagFacet->setSize(100);
$tagFacet->setScript(
                "doc['location'].empty ? null : ceil(doc['location'].arcDistanceIn".$unit."(".
                $entries->getLocationLatitude().", ".
                $entries->getLocationLongitude().")) + '|' + doc['location_name'].value
            + '|' + doc['location_id'].value"
            );

我做错了什么?

如果我测试这个:

"aggs": {
        "location_radius": {
            "terms": {
                "field": "location_facet",
                "size": 10,
                "script": "doc['location'].empty ? null : ceil(doc['location'].arcDistanceInKm(51.2249429, 6.7756524))"
            }
        }
    },

我收到错误:

"type": "script_exception",
               "reason": "failed to run inline script [doc['location'].empty ? null : ceil(doc['location'].arcDistanceInKm(51.2249429, 6.7756524))] using lang [groovy]",
               "caused_by": {
                  "type": "illegal_argument_exception",
                  "reason": "Negative position"
               }

解决方案:我可以使用的所有文档字段也需要"索引":" not_analyzed"。

0 个答案:

没有答案