1
votes

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
1
Can you show what you get when running curl -XGET localhost:9200/your_index ? - Val
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 } } }} }} - MohanG
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. - Val
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 - MohanG
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 - Val

1 Answers

1
votes

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