I am using Facet Terms to get all the unique values and their count for a field. And I am getting wrong results.
term: web
Count: 1191979
term: misc
Count: 1191979
term: passwd
Count: 1191979
term: etc
Count: 1191979
While the actual result should be:
term: WEB-MISC /etc/passwd
Count: 1191979
Here is my sample query:
{
"facets": {
"terms1": {
"terms": {
"field": "message"
}
}
}
}
If reindexing is an option, it would be the best to change mapping and mark this fields as not_analyzed
You can use multi field type if keeping an analyzed version of the field is desired:
This way, you can continue using
your_fieldin the queries, while running facet searches usingyour_field.untouched.Alternatively, if this field is stored, you can use a script field facet instead:
As the last resort, if this field is not stored, but record source is stored in the index, you can try this:
The first solution is the most efficient. The last solution is the least efficient and may take a lot of time on a large index.