Step 1:
Created an index on elastic search http://localhost:9200/shop with below mapping.json
{
"cloth" :
{
"properties" :
{
"name" : { "type" : "string", "index" : "analyzed" },
"variation" :
{
"type" : "nested",
"properties" :
{
"size" :
{
"type" : "string", "index" : "not_analyzed"
},
"color" :
{
"type" : "string", "index" : "not_analyzed"
}
}
}
}
}
}
GET: http://localhost:9200/shop/_mapping/cloth
HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Content-Length: 518
{"shop":{"mappings":{"cloth":{"properties":{"cloth":{"properties":{"properties":{"properties":{"name":{"properties":{"index":{"type":"string"},"type":{"type":"string"}}},"variation":{"properties":{"properties":{"properties":{"color":{"properties":{"index":{"type":"string"},"type":{"type":"string"}}},"size":{"properties":{"index":{"type":"string"},"type":{"type":"string"}}}}},"type":{"type":"string"}}}}}}},"name":{"type":"string"},"variation":{"properties":{"color":{"type":"string"},"size":{"type":"string"}}}}}}}}
Step 2:
Inserted the data with given below data.json http://localhost:9200/shop/cloth/?_create
{
"name" : "Test shirt",
"variation" : [
{ "size" : "XXL", "color" : "red" },
{ "size" : "XL", "color" : "black" }
]
}
Step 3:
Tried searching with given query.json
http://localhost:9200/shop/cloth/_search
{
"query" : {
"nested" : {
"path" : "variation",
"query" : {
"bool" : {
"must" : [
{ "term" : { "variation.size" : "XXL" } },
{ "term" : { "variation.color" : "black" } }
]
}
}
}
}
}
Below error is followed
HTTP/1.1 400 Bad Request Content-Type: application/json; charset=UTF-8 Content-Length: 519
{"error":{"root_cause":[{"type":"query_parsing_exception","reason":"[nested] nested object under path [variation] is not of nested type","index":"shop","line":4,"col":1}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"shop","node":"6U9SA_SDRJKfw1bRxwH8ig","reason":{"type":"query_parsing_exception","reason":"[nested] nested object under path [variation] is not of nested type","index":"shop","line":4,"col":1}}]},"status":400}
What is the way to search with queries nested ? Is there any proper method to load mapping file into search cluster ?
curl -XGET localhost:9200/shop/_mapping/cloth
? – Valcurl -XGET localhost:9200/shop/_mapping/cloth
I don't think it was the case – Val