I am unable to perform a significant terms aggregation using a field that is an array. My Javascript query looks like this:
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
}
}
}
}
})
I get this error:
(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.
My mapping looks like this:
{
index: 'myIndex',
type: 'users',
body: {
properties: {
'myField': []
}
}
}
I know that I don't need to explicitly map array data types, but I do it so I can easily see what fields I have for a certain type
. Following the error message I would change my mapping to look like this:
...
properties: {
myField: {
fielddata: "true"
}
}
...
However, this results in this error:
Error: [mapper_parsing_exception] No type specified for field [myField]
If I were to then add a type: ... properties: { myField: { type: [], fielddata: "true" } } ... I would get this error:
[mapper_parsing_exception] No handler for type [[]] declared on field [myField]
Currently, the data I am aggregating is from data that is seeded through the Javascript client library completely using the Update API constructed with this:
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
}
Hits from this query curl -XGET 'localhost:9200/myIndex/users/_search?pretty'
would then look like this:
...
{
"_index" : "myIndex",
"_type" : "users",
"_id" : "someuserid",
"_score" : 1.0,
"_source" : {
"myField" : [
"someFieldId1",
"someFieldId1",
"someFieldId2"
]
}
},
...
How can I properly perform a significant terms aggregation using a field that is an array?