Search code examples
elasticsearchelastic-stackelasticsearch-5elasticsearch-java-api

Elasticsearch: How to add nested datatype using Java api?


Example::

"price":{  
       "type":"nested",  --> how to add this using java api 
       "properties":{  
          "activity_price":{  
             "type":"double"
          },
          "multimedia_price":{  
             "type":"double"
          },
          "transportation_price":{  
             "type":"double"
          }
       }
    }

Actually I want to add "type" :"nested" in mapping.json
To find nested object, I am using nested query. But getting "[nested] failed to find nested object under path [...]".

Appreciate your help.


Solution

  •     "nested" : {
          "query" : {
            "bool" : {
              "must" : [
                {
                  "match" : {
                    "price.activity_price" : {
                      "query" : 1.0,
                    }
                  }
                }]
            }
          },
          "path" : "price",
          "ignore_unmapped" : false,
          "score_mode" : "none",
          "boost" : 1.0
        }
    

    This is how nested query supposed to be. Finally error has been gone and returned expected result.