Dirkos
Dirkos

Reputation: 676

Parse error nested object for Elasticsearch

I receive the following error during a search on Elasticsearch.

QueryParsingException[[dev_app] [nested] nested object under path [contactNames] is not of nested type];

While checking the actual documentation the below request object is valid https://www.elastic.co/guide/en/elasticsearch/reference/1.6/query-dsl-nested-query.html

This is the request object:

[
  {
    "query": {
      "bool": {
        "must": [
          {
            "constant_score": {
              "query": {
                "match": {
                  "contactBookId": {
                    "query": 15496
                  }
                }
              }
            }
          },
          {
            "constant_score": {
              "query": {
                "nested": {
                  "path": "contactNames",
                  "query": {
                    "bool": {
                      "must": [
                        {
                          "match": {
                            "contactNames.fullName": {
                              "query": "fewafwa"
                            }
                          }
                        },
                        {
                          "match": {
                            "contactNames.nameIndex": {
                              "query": "1"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        ]
      }
    },
    "size": 100
  }
]

Thanks for the help

Upvotes: 1

Views: 719

Answers (2)

Dirkos
Dirkos

Reputation: 676

The issue was that the indexes where not populated in Elasticsearch. Therefor the error was a bit odd

Upvotes: 1

Evaldas Buinauskas
Evaldas Buinauskas

Reputation: 14077

Review your index mappings, contactNames needs to be nested type.

It should look like this (adopt it to your needs):

{
  "mappings": {
    "yourType": {
      "properties": {
        "contactNames": {
          "type": "nested",
          "properties": {
            "fullName": {
              "type": "string"
            },
            "nameIndex": {
              "type": "integer"
            }
          }
        }
      }
    }
  }
}

Then it's not going to throw you an exception and work as expeted.

Upvotes: -1

Related Questions