Multiple inner hits for the same path

Inner hit result contains more hits as i expect.

for code/_id: 2757 inner hit "inner_hit_1" and for code/_id: 1342 "inner hit_2" is unnecessary
How can I get the correct result ?

elastic version: 6.4.1

query:

"should": [
	{
	  "bool": {
		"must": [
		  {
			"term": {
			  "code": {
				"value": "1342"
			  }
			}
		  },
		  {
			"nested": {
			  "query": {
				"bool": {
				  "must": [
					{
					  "term": {
						"snapshots.AnnualConsumptionEstimation": {
						  "value": "-6942"
						}
					  }
					},
					{
					  "query_string": {
						"default_field" : "snapshots.Name",
						"query": "*longtext*"
					  }
					}
				  ]
				}
			  },
			  "path": "snapshots",
			  "inner_hits": {
				"name": "inner_hit_1"
			  }
			}
		  }
		]
	  }
	},
	{
	  "bool": {
		"must": [
		  {
			"term": {
			  "code": {
				"value": "2757"
			  }
			}
		  },
		  {
			"nested": {
			  "query": {
				"bool": {
				  "must": [
					{
					  "range": {
						"snapshots.Date": {
						  "from": null,
						  "to": "2016-09-09"
						}
					  }
					},
					{
					  "term": {
						"snapshots.VoltageLevel": {
						  "value": "400"
						}
					  }
					}
				  ]
				}
			  },
			  "path": "snapshots",
			  "inner_hits": {
				"name": "inner_hit_2"
			  }
			}
		  }
		]
	  }
	}
]

result:

"hits": [
  {
	"_id": "2757",
	"_source": {
	  "code": "2757",
	  "snapshots": [
		{
		  "Date": {
			"gte": "2016-09-08T22:00:00Z",
			"lt": "2017-09-13T22:00:00Z"
		  },
		  "VoltageLevel": 400,
		  "AnnualConsumptionEstimation": -4762,
		  "Name": "aaaaaaaaa"
		},
		{
		  "Date": {
			"gte": "2017-09-13T22:00:00Z",
			"lt": "2018-12-31T23:00:00Z"
		  },
		  "VoltageLevel": 400,
		  "AnnualConsumptionEstimation": -5697,
		  "Name": "ccccccccc"
		}
	  ]
	},
	"inner_hits": {
	  "inner_hit_1": {
		"hits": {
		  "hits": []
		}
	  },
	  "inner_hit_2": {
		"hits": {
		  "hits": [
			{
			  "_id": "2757",
			  "_nested": {
				"field": "snapshots",
			  },
			  "_source": {
				"Date": {
				  "gte": "2016-09-08T22:00:00Z",
				  "lt": "2017-09-13T22:00:00Z"
				},
				"VoltageLevel": 400,
				"AnnualConsumptionEstimation": -4762,
				"Name": "aaaaaaaaa"
			  }
			}
		  ]
		}
	  }
	}
  },
  {
	"_id": "1342", 
	"_source": {
	  "code": "1342",
	  "snapshots": [
		{
		  "Date": {
			"gte": "2016-07-20T22:00:00Z",
			"lt": "2017-07-11T22:00:00Z"
		  },
		  "VoltageLevel": 400,
		  "AnnualConsumptionEstimation": -7728,
		  "Name": "longtext"
		},
		{
		  "Date": {
			"gte": "2017-07-11T22:00:00Z",
			"lt": "2017-12-31T23:00:00Z"
		  },
		  "VoltageLevel": 400,
		  "AnnualConsumptionEstimation": -7259,
		  "Name": "longtext"
		},
		{
		  "Date": {
			"gte": "2017-12-31T23:00:00Z",
			"lt": "2027-01-16T23:00:00Z"
		  },
		  "VoltageLevel": 400,
		  "AnnualConsumptionEstimation": -6942,
		  "Name": "longtext"
		}
	  ]
	},
	"inner_hits": {
	  "inner_hit_1": {
		"hits": {
		  "hits": [
			{
			  "_id": "1342",
			  "_nested": {
				"field": "snapshots",
			  },
			  "_source": {
				"Date": {
				  "gte": "2017-12-31T23:00:00Z",
				  "lt": "2027-01-16T23:00:00Z"
				},
				"VoltageLevel": 400,
				"AnnualConsumptionEstimation": -6942,
				"Name": "longtext"
			  }
			}
		  ]
		}
	  },
	  "inner_hit_2": {
		"hits": {
		  "hits": [
			{
			  "_id": "1342",
			  "_nested": {
				"field": "snapshots",
			  },
			  "_source": {
				"Date": {
				  "gte": "2016-07-20T22:00:00Z",
				  "lt": "2017-07-11T22:00:00Z"
				},
				"VoltageLevel": 400,
				"AnnualConsumptionEstimation": -7728,
				"Name": "longtext"
			  }
			}
		  ]
		}
	  }
	}
  }
]

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