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.
That's the issue. If you don't specify
"type": "nested"
explicitly, thenpredicates
won't be of typenested
but of typeobject
instead, and your query won't work as you can see.You need to explicitly define
predicates
asnested
in your mapping, there's no other way.UPDATE
Your native query should look like this: