I'm executing a search query on an ElasticSearch index that is giving me strange results. I want to find all documents where the product.id = 209349
:
{
"index": "products",
"from": 0,
"size": 100,
"body": {
"query": {
"filtered": {
"filter": [
{
"term": {
"product.id": 209349
}
}
]
}
}
}
}
However, the results are returning me a document where product.id = 83875
. What I noticed is the product.variant.id
equals 209349
... What's going on here?
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "products",
"_type": "product",
"_id": "UPC-83875",
"_score": 1,
"_source": {
"mpn": "UPC-83875",
"product_count": 1,
"price": "448.00",
"price_discount_amount": null,
"product": [
{
"id": 83875,
"posted_on": "2014-07-23 22:08:36",
"status_id": 3,
"sku": "23469984",
"mpn": "UPC-83875",
"name": "Laser Toner Cartridge Set Black Cyan Yellow Magenta",
"description": "",
"has_image": true,
"currency_id": 1,
"price": "448.00",
"variant": [
{
"id": 209349,
"sku": "23469984",
"name": null,
"price": "448.00",
"discount_amount": null,
"price_total": "448.00",
"has_image": false
}
]
}
]
}
}
]
}
}
Here's the schema:
{
"dynamic": "strict",
"properties": {
"mpn": {
"type": "string",
"index": "not_analyzed"
},
"price": {
"type": "double"
},
"price_discount_amount": {
"type": "double"
},
"product": {
"properties": {
"id": {
"type": "long"
},
"posted_on": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"status_id": {
"type": "long"
},
"sku": {
"type": "string",
"index": "not_analyzed"
},
"mpn": {
"type": "string",
"index": "not_analyzed"
},
"name": {
"type": "string",
"analyzer": "english"
},
"description": {
"type": "string",
"analyzer": "english"
},
"has_image": {
"type": "boolean"
},
"price": {
"type": "double"
},
"price_discount_amount": {
"type": "double"
},
"currency_id": {
"type": "long"
},
"variant": {
"properties": {
"id": {
"type": "long"
},
"sku": {
"type": "string",
"index": "not_analyzed"
},
"name": {
"type": "string",
"analyzer": "english"
},
"discount_amount": {
"type": "double"
},
"price": {
"type": "double"
},
"price_total": {
"type": "double"
},
"has_image": {
"type": "boolean"
}
}
}
}
}
}
}
Edit/Solved: It appears the issue was the fact that my index _type
is named product
as well as the inner object. So what was happening was ES matched <_type>.id
(kinda like doing *.id
) and it would match the variant.id
because it was an id
field.
The correct name to use is apparently product.product.id
which ends up being a full path.
This behavior is apparently to appease some users long ago: https://github.com/elastic/elasticsearch/issues/3005