I want to filter on an inner object but I'm not able to get my data. I have the following elasticsearch mapping:
{
"settings" : {
"number_of_shards" : 1,
"analysis" : {
"filter" : {
"technologies_synonym" : {
"type" : "synonym",
"synonyms_path" : "elasticsearch/synonyms/technologies.txt"
}
},
"analyzer" : {
"technologies_synonyms" : {
"tokenizer" : "whitespace",
"filter" : ["standard", "lowercase", "stop", "technologies_synonym"],
"type" : "custom"
}
}
}
},
"mappings": {
"company" : {
"properties" : {
"name" : { "type" : "string", "store" : "yes" },
"logo" : { "type" : "string", "store" : "yes" },
"website" : { "type" : "string", "store" : "yes" },
"employees" : { "type" : "string", "store" : "yes" },
"technologies" : { "type" : "string", "store" : "yes", "analyzer" : "technologies_synonyms" },
"locations" : {
"properties": {
"city" : { "type" : "string", "store" : "yes" },
"country" : { "type" : "string", "store" : "yes" },
"coordinates" : { "type" : "geo_point", "store" : "yes" },
}
}
}
}
}
}
My mapping use an inner object for locations, because a company can be located in several places. I also tried to replace the inner object by a nested.
{
"mapping" : {
"properties" : {
# ...
"locations" : { "type" : "nested" }
}
}
When I query my companies objects on the other fields, I'm able to get the expecting results, but when I filter on a country I have no results.
Tried queries:
curl 'http://localhost:9200/myapp/company/_search?pretty=true' -XPOST -d '{
"query": {
"filtered": {
"query": { "match_all": {} },
"filter": {
"nested": {
"path": "locations",
"filter": {
"bool": {
"must": [
{
"term": { "locations.country": "France" }
}
]
}
}
}
}
}
}
}
curl 'http://localhost:9200/tekusage/company/_search?pretty=true' -XPOST -d '{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"technologies": "ruby"
}
},
{
"term": {
"company.locations.country": "France"
}
},
{
"term": {
"company.locations.city": "Lille"
}
}
]
}
}
}
}
}'
Do you have some idea to help me to get my data ?
Thanks, Kevin