【发布时间】:2017-10-27 22:18:06
【问题描述】:
我无法使用数组字段执行重要的术语聚合。我的 Javascript 查询如下所示:
client.search({
index: myIndex,
body: {
query: {
terms: {
myField: ['someuserid']
// also tried with same result... myField: 'someuserid'
}
},
aggregations: {
recommendations: {
significant_terms: {
field: "myField",
min_doc_count: 1
}
}
}
}
})
我收到此错误:
(node:13105) UnhandledPromiseRejectionWarning: Unhandled promise rejection
(rejection id: 1): Error: [illegal_argument_exception] Fielddata is disabled
on text fields by default. Set fielddata=true on [myField] in order to
load fielddata in memory by uninverting the inverted index. Note that this can
however use significant memory.
我的映射如下所示:
{
index: 'myIndex',
type: 'users',
body: {
properties: {
'myField': []
}
}
}
我知道我不需要显式映射数组数据类型,但我这样做是为了可以轻松查看某个 type 的字段。根据错误消息,我会将映射更改为如下所示:
...
properties: {
myField: {
fielddata: "true"
}
}
...
但是,这会导致以下错误:
Error: [mapper_parsing_exception] No type specified for field [myField]
如果我要添加一个类型: ... 特性: { 我的领域:{ 类型: [], 字段数据:“真” } } ... 我会收到这个错误:
[mapper_parsing_exception] No handler for type [[]] declared on field [myField]
目前,我正在聚合的数据来自通过 Javascript 客户端库完全使用由以下内容构建的更新 API 播种的数据:
const update = {
"upsert": {
"myField": ['myValue']
},
"script": {
"inline": "ctx._source.myField.add(params.itemField)",
"params": {
"itemField": 'itemValue'
}
}
};
const req = {
index: 'myIndex',
type: 'users',
id: 'someuserid',
body: update
}
来自此查询 curl -XGET 'localhost:9200/myIndex/users/_search?pretty' 的命中将如下所示:
...
{
"_index" : "myIndex",
"_type" : "users",
"_id" : "someuserid",
"_score" : 1.0,
"_source" : {
"myField" : [
"someFieldId1",
"someFieldId1",
"someFieldId2"
]
}
},
...
如何使用数组字段正确执行重要术语聚合?
【问题讨论】:
标签: javascript arrays elasticsearch