Hello guys,
I am having trouble querying nested documents from ElasticSearch. Below you can find my schema and some example queries incl. data.
#!/bin/bash curl -XPUT 'http://localhost:9200/search/' curl -XPUT "http://localhost:9200/search/models/_mapping" -d '{ "models": { "_timestamp": {"enabled": true, "store": true}, "properties": { "categories": {"type": "string"}, "categoryTree": {"type": "string"}, "products": { "type": "nested", "properties": { "id": {"type": "string"}, "title": {"type": "string"}, "description": {"type": "string"}, "color": {"type": "string"}, "variants": { "type": "nested", "properties": { "id": {"type": "string"}, "size": {"type": "string"}, "sellers": { "type": "nested", "properties": { "id": {"type": "string"}, "deepLinkUrl": {"type": "string"}, "stock": {"type": "long"}, "price": { "type": "nested", "properties": { "isoCode": {"type": "string"}, "original": {"type": "double"}, "current": {"type": "double"}, "discountPercentage": {"type": "long"} } }, "shippingMethods": { "type": "nested", "properties": { "id": {"type": "string"}, "carrier": {"type": "string"}, "deliveryMethod": {"type": "string"}, "deliveryCostsSingleItem": { "type": "nested", "properties": { "isoCode": {"type": "string"}, "original": {"type": "double"}, "current": {"type": "double"}, "discountPercentage": {"type": "long"} } }, "deliveryCostsMultiItem": { "type": "nested", "properties": { "isoCode": {"type": "string"}, "original": {"type": "double"}, "current": {"type": "double"}, "discountPercentage": {"type": "long"} } }, "deliveryTimeMin": {"type": "long"}, "deliveryTimeMax": {"type": "long"}, "handlingTimeMin": {"type": "long"}, "handlingTimeMax": {"type": "long"} } } } } } }, "images": { "type": "nested", "properties": { "type": {"type": "string"}, "urls": { "type": "nested", "properties": { "small": {"type": "string"}, "medium": {"type": "string"}, "large": {"type": "string"} } } } }, "attributes": { "type": "nested", "properties": { "id": {"type": "string"}, "value": {"type": "string"}, "title": {"type": "string"} } } } } } } }'
I try and query the data with the following queries:
#!/bin/bash # this is working - notice default_field = _all curl -XPOST "http://localhost:9200/search/models/_search" -d '{ "query": { "bool": { "must": [ { "query_string": { "default_field": "_all", "query": "Blau" } } ] } } }' # this is not working, trying to limit the search to default_field = models.products.color # it seems this happens with ALL nested documents, as i can easily filter by e.g. models.categories curl -XPOST "http://localhost:9200/search/models/_search" -d '{ "query": { "bool": { "must": [ { "query_string": { "default_field": "models.products.color", "query": "Blau" } } ] } } }' # doesn't work either, despite using nested paths. curl -XPOST "http://localhost:9200/search/models/_search" -d '{ "query": { "bool": { "must": [ { "nested": { "path": "models.products", "query": { "bool": { "must": [ { "match": { "models.products.color": "Blau" }} ] }}}} ] }}}'
I really have no clue what I'm doing wrong here. Any help would be highly appreciated.
Example data can be found here: http://pastebin.com/WG3xj2qz