1

I am getting this error when trying to query nested fields, this question seems repeating but with little changes, while setting mappings of fields I didn't specify nested but created nested mapping. now when I am trying to query do Neptune full-text search query using gremlin it is working but when I am trying to do a native query it is giving this error :

failed to create a query: [nested] nested object under path [predicates] is not of nested type

Elasticsearch index mapping

{
  "amazon_neptune" : {
    "mappings" : {
      "properties" : {
        "aggregateId" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "document_type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "entity_id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "entity_type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "predicates" : {
          "properties" : {
            "group_name" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "analyzer" : "autocomplete_analyzer",
                  "search_analyzer" : "standard"
                }
              }
            },
            "question" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "analyzer" : "questions_auto_complete_analyzer",
                  "search_analyzer" : "standard"
                }
              }
            },
            "suggestion" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "analyzer" : "autocomplete_analyzer",
                  "search_analyzer" : "standard"
                }
              }
            },
            "type" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            },
            "user_name" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "analyzer" : "autocomplete_analyzer",
                  "search_analyzer" : "standard"
                }
              }
            }
          }
        }
      }
    }
  }
}

gremlin query which is working

g.withSideEffect('Neptune#fts.endpoint',ES Endpoint).withSideEffect('Neptune#fts.queryType', 'match').V().has('suggestion','Neptune#fts life').limit(5).valueMap().toList()

Elasticsearch query giving error:

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "entity_type": "suggestions"
                    }
                },
                {
                    "term": {
                        "document_type": "vertex"
                    }
                },
                {
                    "nested": {
                        "path": "predicates",
                        "query": {
                            "nested": {
                                "path": "predicates.suggestion",
                                "query": {
                                    "match": {
                                        "predicates.suggestion.value": "life"
                                    }
                                }
                            }
                        }
                    }
                }
            ]
        }
    }
}

Please let me know if there is anything wrong with this query.

2 Answers 2

2

I didn't specify nested but created nested mapping

That's the issue. If you don't specify "type": "nested" explicitly, then predicates won't be of type nested but of type object instead, and your query won't work as you can see.

You need to explicitly define predicates as nested in your mapping, there's no other way.

UPDATE

Your native query should look like this:

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "entity_type": "suggestions"
                    }
                },
                {
                    "term": {
                        "document_type": "vertex"
                    }
                },
                {
                    "match": {
                        "predicates.suggestion.value": "life"
                    }
                }
            ]
        }
    }
}
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks, @Val I already tried this, working fine. But how Amazon Neptune gremlin is able to do the same if the native query does not allow that. How can an external tool using the same service is working fine?
gremlin is not doing a nested query for sure, or it would error out as well. it's doing a normal query and the result is probably not what you want
But gremlin is returning the expected result, is there any other way I can query something like this?
then if gremlin that is doing a non-nested query returns the correct results, why do you want to include nested in your native query? i.e. your native query is not equivalent to the one gremlin is making
I don't know actually how gremlin queries under the hood but the way Neptune store the data is the same as mine.
|
1

Adding a working example with index data, mapping, search query and search result

Index Mapping:

{
  "mappings":{
    "properties":{
      "predicates":{
        "type":"nested",
        "properties":{
          "suggestion":{
            "type":"nested",
            "properties":{
              "value":{
                "type":"text"
              }
            }
          }
        }
      }
    }
  }
}

Index Data:

 {
      "predicates": [
        {
          "suggestion": [
            {
              "value": "life"
            }
          ]
        }
      ]
    }

Running the same search query, as given in the question:

Search Result:

"hits": [
      {
        "_index": "stof_64312693",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "predicates": [
            {
              "suggestion": [
                {
                  "value": "life"
                }
              ]
            }
          ]
        }
      }
    ]

2 Comments

I don't see the reason of making suggestion nested if it only has a single property.
I am implementing this for Amazon Neptune FTS, this is how neptune queries on elasticsearch i.e this schema is provided in Neptune docs.

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.