Hi,
I've been working with ES in the last two months and each day I discover new fantastic features.
I would like to know if it it possible to implement the following case:
I have many docs indexed in the ES server, with a location field that stores location information (locality, region and more). One example of the location field (type string) is:
location: 'Brooklyn, New York, USA'
I would like to do a faceted search and have those results grouped by location information. However if I do the following request:
curl -XGET http://localhost:9200/test/_search?pretty=true -d '{
"query": {
"query_string" :{
"fields" : ["title", "description", "location"],
"query": "xxx"
}
},
"facets": {
"location": {
"terms": {
"field" : "location"
}
}
}
}'
I do obtain the results grouped by location, but by each of the terms in location field, this is:
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : { ...
},
"facets" : {
"location" : {
"_type" : "terms",
"missing" : 15,
"terms" : [ {
"term" : "USA",
"count" : 10
}, {
"term" : "New",
"count" : 4
}, {
"term" : "York",
"count" : 4
}, {
"term" : "Brooklyn",
"count" : 2
},]
}
}
}
If I declare in the mapping the location field as not analyzed, then the whole field is taken as a facet.
I would like an intermediate solution, where the field is analyzed but instead of splitting the term by whitespace, splittiing it by a comma, this is, I would like to obtain a reponse similar to:
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : { ...
},
"facets" : {
"location" : {
"_type" : "terms",
"missing" : 15,
"terms" : [ {
"term" : "USA",
"count" : 10
}, {
"term" : "New York",
"count" : 4
} {
"term" : "Brooklyn",
"count" : 2
},]
}
}
}
I have been searching for this in the ES guide, and maybe setting an appropriate analyzer could make it but I cant guess how to do it, even if it is a correct approach.
I appreciate any help or guidance. Thanks in advance!
Tania