# Multiple inner hits for the same path

**URL:** <https://discuss.elastic.co/t/multiple-inner-hits-for-the-same-path/149972>\
**Category:** Elasticsearch\
**Created:** [September 26, 2018, 9:47am UTC](https://discuss.elastic.co/t/multiple-inner-hits-for-the-same-path/149972 "2018-09-26T09:47:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lbugar](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lbugar](https://discuss.elastic.co/u/lbugar)\
**Post date:** [September 26, 2018, 9:47am UTC](https://discuss.elastic.co/t/multiple-inner-hits-for-the-same-path/149972/1 "2018-09-26T09:47:52Z")

</div>

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"
			  }
			}
		  ]
		}
	  }
	}
  }
]
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 24, 2018, 9:48am UTC](https://discuss.elastic.co/t/multiple-inner-hits-for-the-same-path/149972/2 "2018-10-24T09:48:05Z")

</div>

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