I have configured my Elastic Search implementation to facet the results by an id in the mapping and when I display that facet to the user I need to be able to show the human-readable name that represents it. The data I need is all present in the mapping, but I am not sure how I can return it as part of the facet. Surely it is possible?
Given the following example, I'd like to the facet to give me some way to correlate the thingId
to thingName
(or any other thing
property that might be needed):
Mapping
{
thingId,
thingName
}
Facet Query
{
"facets":{
"things":{ "terms":{ "field":"thingId" } }
}
}
Result
{
"hits":{
"total":3,
"max_score":1.0,
"hits":[
...
]
},
"facets":{
"things":{
"_type":"terms",
"missing":0,
"total":3,
"other":0,
"terms":[
{
"term":"5",
"count":1
},
{
"term":"4",
"count":1
},
{
"term":"2",
"count":1
}
]
}
}
}
Edit
This answer regarding Solr suggests that I facet both properties (thingName
and thingId
) and then just loop over both facet result sets, assuming that the order of items would be the same. I don't know how reliable that would be, but it is an option.
Edit 2
This answer suggests that it's not possible to do what I want without combining the the two fields into a single value and faceting on that: thingId|thingName
. Not ideal.
Edit 3
This answer suggests combining the values together into a single field and faceting on it (as above), but it uses a terms script to achieve the combination, thus not requiring me to index the combined form of the values. Still not perfect, but appears to be the least crappy option.