1

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 ?

5
  • Can you update your question with the output you get form curl -XGET localhost:9200/shop/_mapping/cloth ? Commented Aug 18, 2016 at 11:22
  • How we can insert the mapping, as am using as POST with mapping.json content Commented Aug 18, 2016 at 11:25
  • my bad, sorry, please check my above comment again. Commented Aug 18, 2016 at 11:25
  • Please run this: curl -XGET localhost:9200/shop/_mapping/cloth I don't think it was the case Commented Aug 18, 2016 at 11:28
  • @Val I have simple question: If the declare more Fields in the mapping file and post less columns on the index DB and Perform search on the Index Whether it throws same error as the above question ? Commented Aug 19, 2016 at 6:44

2 Answers 2

1

I think you're not properly creating your index with the cloth mapping. Do it this way:

# delete your index first
curl -XDELETE localhost:9200/shop

# create it properly
curl -XPUT localhost:9200/shop -d '{
  "mappings": {
    "cloth": {
      "properties": {
        "name": {
          "type": "string",
          "index": "analyzed"
        },
        "variation": {
          "type": "nested",
          "properties": {
            "size": {
              "type": "string",
              "index": "not_analyzed"
            },
            "color": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
  }
}'
Sign up to request clarification or add additional context in comments.

Comments

0
{
    "query" : {
        "nested" : {
            "path" : "cloth.variation",
            "query" : {
                "bool" : {
                    "must" : [
                        { "term" : { "cloth.variation.size" : "XXL" } },
                        { "term" : { "cloth.variation.color" : "black" } }
                    ]
                }
            }
        }
    }
}

1 Comment

You should add some explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.