Elasticsearch nested mapping query not working- JAVA?


(Mohan Ghimire) #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


(Christoph) #2

Hi,

can you make sure your mapping is correct? I tried reproducing this with a minimal example (see below). The Query is what you'd get when you send the rest output of your java example to a cluster. This doesn't return the error you described but returns the document:


PUT index
{
  "mappings": {
    "type": {
      "properties": {
        "name": {
          "type": "keyword"
        },
        "price":{  
           "type":"nested",
           "properties":{  
              "activity_price":{  
                 "type":"double"
              },
              "multimedia_price":{  
                 "type":"double"
              },
              "transportation_price":{  
                 "type":"double"
              }
           }
        }
      }
    }
  }
}

PUT /index/type/1
{
	"name": "Test",
	"price": {
	  "activity_price" : 1.04,
	  "multimedia_price" : 4.546,
	  "transportation_price" : 3.0
	}
}

GET /index/type/_search
{
  "query": {
    "nested": {
      "path": "price",
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "price.activity_price": {
                  "query": 1.04
                }
              }
            }
          ]
        }
      }
    }
  }
}

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.