Querying on Nested Object retrieving wrong data

Hi,

I'm trying to create a sub query that I'm having trouble with. Here's sample data:

{
                        "Id": "5b0ef14df5a3f81d049c2a34",
                        "Active": true,
                        "EntityId": 3638236,
                        "FormId": 906,
                        "FormName": "aItem",
                        "OrganizationId": 1,
                        "OfficeId": 1,
                        "VisibilityId": 0,
                        "String1": "textbox",
                        "String2": "email@asdf.com",
                        "String3": "asdf",
                        "String4": "textarea",
                        "Date1": "2018-05-30T18:45:00Z",
                        "Double1": 1234,
                        "Bool1": false,
                        "SelectList1": "Option 2",
                        "RadioButtonList1": "Option 3",
                        "CheckBoxList1": [
                            {
                                "Name": "Option 1",
                                "Value": false
                            },
                            {
                                "Name": "Option 2",
                                "Value": true
                            },
                            {
                                "Name": "Option 3",
                                "Value": true
                            }
                        ]
                    }
                ]
},
{
                        "Id": "5b0ef1bcf5a3f81d049c2a9c",
                        "Active": true,
                        "EntityId": 2726738,
                        "FormId": 906,
                        "FormName": "aItem",
                        "OrganizationId": 1,
                        "OfficeId": 1,
                        "VisibilityId": 0,
                        "String1": "textbox2",
                        "String2": "asdfasdf@asdf.com",
                        "String3": "asdfasdf",
                        "String4": "textarea2",
                        "Date1": "2018-05-27T18:47:00Z",
                        "Double1": 123456,
                        "Bool1": true,
                        "SelectList1": "Option 1",
                        "RadioButtonList1": "Option 2",
                        "CheckBoxList1": [
                            {
                                "Name": "Option 1",
                                "Value": true
                            }
                        ]
}

CheckboxList1 is a nested object

What I want to do is query the document where CheckBoxList1 "Name" is "Option 1" and "Value" is true (retrieve the second document).
If I do something like (this may be wrong, I've tried to simplify the document for this post):

{"from":0,"size":25,
	"query":
	{
				"nested":{
					"query":{
						"bool":{
							"must":[
                                {"match":{"CheckBoxList1.Name": "Option 1"}},
								{"term":{"CheckBoxList1.Value":{"value":true}}}
								]
							
						}},"path":"CheckBoxList1"}}
	
}

It matches both documents. What am I doing wrong?

What do you meany by "it matches both documents"? both nested documents?

Results are displayed as parent documents with all their nested documents (matched and unmatched). If you would like to know what particular nested documents matched the query, you can use inner hits option of the nested query. For example:

"nested" : {
	"path" : "CheckBoxList1",
	"query" : {
		....
		
	},
	"inner_hits" : {}
}

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