I have an elastic document as below.
{
"process_id" : "123",
"user_info" : [{
"first_name":"A",
"last_name: "B"
}]
}
{
"process_id" : "123",
"user_info" : [{
"first_name":"C",
"last_name: "B"
},
{"first_name" : "A",
"last_name":"D"
} ]
}
Scenario 1:
I have not set the nested type to the "user_info" field. I search for "process_id" as 123 and first_name as A and last_name as B, I get both the documents in the result.
Scenario 2:
The search returns an error. It looks like I will not be able to search for the nested item and the one that is in the parent.
The query is as below:
{
"query": {
"query_string": {
"query": "process_id:123",
"nested": {
"path": "user_info",
"query": {
"query_string": {
"query": "(user_info.first_name:A AND user_info.last_name:B"
}
}
}
} } }
The error response is as below.
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[query_string] unknown token [START_OBJECT] after [nested]",
"line": 1
}
],
"type": "parsing_exception",
"reason": "[query_string] unknown token [START_OBJECT] after [nested]",
"line": 1,
},
"status": 400
}
The ideal response should be when I search for process_id as 123, first_name as A and last_name as B, Only the first document has to be returned.
Note: The attribute names are kept generic in purpose so that the actual can be illustrated.