在使用 field1 值找到 params 中的值后,我嘗試使用找到的欄位值進行聚合。
GET /_search
{
"size" : 0,
"query" : {
"ids" : {
"types" : [ ],
"values" : [ "docId1", "docId2" .... ]
}
},
"aggs": {
"countries": {
"terms": {
"script": {
"params": {
"field1": "country",
"field2": "test",
"field3": "test"
},
"inline": "def syn = params['field1']; doc[syn].value"
}
}
}
}
}
它失敗并顯示以下訊息。
"failures": [
{
"reason": {
"type": "script_exception",
"reason": "failed to run inline script [def syn = params['field1']; doc[syn].value] using lang [groovy]",
"caused_by": {
"type": "missing_property_exception",
"reason": "No such property: params for class: 8f7af04189385c7d3c546861d4817e4ae8ca75f5"
}
}
}
]
如果我直接輸入它而不從params中匯入值,它會正常聚合。
GET /_search
{
"size" : 0,
"query" : {
"ids" : {
"types" : [ ],
"values" : [ "docId1", "docId2" .... ]
}
},
"aggs": {
"countries": {
"terms": {
"script": {
"params": {
"field1": "country",
"field2": "test",
"field3": "test"
},
"inline": "doc['country'].value"
}
}
}
}
}
像這樣:
{
...
"aggregations": {
"how_to_merge": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "KR",
"doc_count": 90
},
{
"key": "JP",
"doc_count": 83
},
{
"key": "US",
"doc_count": 50
},
{
"key": "BE",
"doc_count": 9
}
]
}
}
}
我正在使用 groovy 和 elasticsearch 2.2 版
我不能使用 Python 或 JavaScript,這需要安裝額外的插件。
為什么我無法獲取 params 中的值?
uj5u.com熱心網友回復:
如果我沒記錯的話,在 2.2 中,您不需要params.在腳本源中為引數添加前綴。像這樣嘗試:
"aggs": {
"countries": {
"terms": {
"script": {
"params": {
"field1": "country",
"field2": "test",
"field3": "test"
},
"inline": "def syn = field1; doc[syn].value"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/375330.html
標籤:弹性搜索 时髦的 弹性搜索聚合 elasticsearch-dsl
