1

I've set my one field to nested type. I followed as per this documentation https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-joining-queries.html#java-query-dsl-nested-query

Below is the snippet

"price":{  
           "type":"nested",
           "properties":{  
              "activity_price":{  
                 "type":"double"
              },
              "multimedia_price":{  
                 "type":"double"
              },
              "transportation_price":{  
                 "type":"double"
              }
           }
        }

While performing query

QueryBuilders.nestedQuery("price", QueryBuilders.boolQuery()
        .must(QueryBuilders.matchQuery("price.activity_price", price)),
            ScoreMode.Max);

I get [nested] nested object under path [price] is not of nested type.

I'm using Elasticsearch 5.1.2

I've three files to create index,mappings and to populate data:- mapping.json

{  
   "settings":{  
      "number_of_shards":1,
      "number_of_replicas":0
   },
   "mappings":{  
      "test_type_table":{  
         "price":{  
            "type":"nested",
            "properties":{  
               "activity_price":{  
                  "type":"double"
               },
               "multimedia_price":{  
                  "type":"double"
               },
               "transportation_price":{  
                  "type":"double"
               }
            }
         }
      }
   }
}

data.json

{ "index" : { "_index" : "test_index", "_type" : "test_type_table", "_id" : "1" } }
{"price": [{"activity_price":"100.00","multimedia_price":"10","transporation_price":"10"}]}

and setup.json

curl -XPOST http://localhost:9200/test_index -d @mapping.json
curl -s -XPOST http://localhost:9200/_bulk --data-binary @data.json
6
  • Can you show what you get when running curl -XGET localhost:9200/your_index ? Commented Jan 31, 2017 at 10:38
  • Hey Val, Please find the response of the curl command below:- "mappings":{ "test_type_table":{ "properties":{ "price":{ "properties":{ "activity_price":{ "type":"text", "fields":{ "keyword":{ "type":"keyword", "ignore_above":256 } } }, "multimedia_price":{ "type":"text", "fields":{ "keyword":{ "type":"keyword", "ignore_above":256 } } }, "transporation_price":{ "type":"text", "fields":{ "keyword":{ "type":"keyword", "ignore_above":256 } } } } }, "title":{ "type":"text", "fields":{ "keyword":{ "type":"keyword", "ignore_above":256 } } }} }} Commented Jan 31, 2017 at 11:40
  • There you go, if you look carefully the price field is not nested, so you must have done something wrong when creating the index. You need to wipe it and create it again with your mapping. Commented Jan 31, 2017 at 12:42
  • Hey Val, I've edited the contain of the post and added the contains of the files that i've used while creating index. Please have a look. Thanks Commented Jan 31, 2017 at 13:13
  • In ES 5, in order to create an index you MUST use -XPUT instead of -XPOST, your index probably wasn't created with your first command, but only when sending the second bulk command Commented Jan 31, 2017 at 13:17

1 Answer 1

1

You need to fix your mapping.json file like this:

{  
   "settings":{  
      "number_of_shards":1,
      "number_of_replicas":0
   },
   "mappings":{  
      "test_type_table":{  
        "properties": {                  <--- this is missing
         "price":{  
            "type":"nested",
            "properties":{  
               "activity_price":{  
                  "type":"double"
               },
               "multimedia_price":{  
                  "type":"double"
               },
               "transportation_price":{  
                  "type":"double"
               }
            }
         }
        }
      }
   }
}

Then you can recreate your index using PUT instead of POST

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

# recreate your index using PUT
curl -XPUT http://localhost:9200/test_index -d @mapping.json
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much Val. That was such a silly mistake.

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.