# How can i run this query just for find first item in a path with 4 items

**URL:** <https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633>\
**Category:** Elasticsearch\
**Created:** [September 25, 2017, 5:06am UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633 "2017-09-25T05:06:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaser/32/109240_2.png) [@yaser](https://discuss.elastic.co/u/yaser)\
**Post date:** [September 25, 2017, 5:06am UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/1 "2017-09-25T05:06:12Z")

</div>

hi , the problem is i want to return range of value of a path that are the same with 4 other items , here is the query:

```
GET composition_value/composition/_search
{
  "query": {
    "nested": {
      "path": "value",
      "query": {
        "bool": {
          "must": [
            {"match": {"value.composition.content.data.events.data.items.name.value": "systolic"}},
            {"range": {"value.composition.content.data.events.data.items.value.magnitude": {"gte": 10,"lte": 40}}}
          ]
        }
      }
    }
  }
}

```

**And the document that i search in it ,is like this :**

```
	               "items": [{
			    		"name": {
 								"value": "Systolic"
> },
> "value": {
> "magnitude": "70",
> "units": "cm[Hg]",
> "_xsi:type": "DV_QUANTITY"
> },
> "_archetype_node_id": "at0004",
> "_xsi:type": "ELEMENT"
> },
						{
							"name": {
								"value": "Diastolic"
							},
							"value": {
								"magnitude": "80",
								"units": "cm[Hg]",
								"_xsi:type": "DV_QUANTITY"
							},
							"_archetype_node_id": "at0005",
							"_xsi:type": "ELEMENT"
						},
						{
							"name": {
								"value": "Mean Arterial Pressure"
							},
							"value": {
								"magnitude": "615",
								"units": "mm[Hg]",
								"_xsi:type": "DV_QUANTITY"
							},
							"_archetype_node_id": "at1006",
							"_xsi:type": "ELEMENT"
						},
						{
							"name": {
								"value": "Pulse Pressure"
							},
							"value": {
								"magnitude": "324",
								"units": "mm[Hg]",
								"_xsi:type": "DV_QUANTITY"
							},
							"_archetype_node_id": "at1007",
							"_xsi:type": "ELEMENT"
						},
						{
							"name": {
								"value": "Comment"
							},
							"value": {
								"value"sasd3213",
								"_xsi:type": "DV_TEXT"
							},
							"_archetype_node_id": "at0033",
							"_xsi:type": "ELEMENT"
						}],
						"_archetype_node_id": "at0003",
						"_xsi:type": "ITEM_TREE"
					}

```

**And i want to check range of "value.magnitude" of "systolic" not items "diastolic , 2 other items"**

**i want to filter the first item with "\_archetype\_node\_id" attribute that point to "at0004"**

tanks

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [September 26, 2017, 6:00pm UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/3 "2017-09-26T18:00:39Z")

</div>

Can you rephrase your question, simplify your example, include the schema and show the output that you would like to get? I re-read your question several times, but I am not really sure what you are trying to achieve. Thanks!

---

<div class="post-metadata">

**Author:** ![yaser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaser/32/109240_2.png) [@yaser](https://discuss.elastic.co/u/yaser)\
**Post date:** [September 27, 2017, 8:38am UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/4 "2017-09-27T08:38:04Z")

</div>

yes of course , the question is how can i query on nested type in elasticsearch ,

this is my document that i save in one nested value in elasticsearch :

and this is the result that i want :

check the range of this path only :

composition.content.data.events.data.items.name.value=="systolic"  
the value of "systolic" is "beside" not "in above path" and the path of systolic is :

composition.content.data.events.data.items.value.magnitude

**but the main problem is here : the path "composition.content.data.events.data.items.value.magnitude" is repeated 4 times , one for systolic of for diastolic and 2 others , but i want get just the systolic** ,

and another thing is i want to select the result that i want by "\_archetype\_node\_id": "at0004", property but i cant .

---

<div class="post-metadata">

**Author:** ![yaser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaser/32/109240_2.png) [@yaser](https://discuss.elastic.co/u/yaser)\
**Post date:** [September 27, 2017, 8:50am UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/6 "2017-09-27T08:50:32Z")

</div>

![Capture](https://us1.discourse-cdn.com/elastic/original/3X/1/3/134274222d68b78d1ca374ef0768d695d36fd891.PNG)

**I want to filter the range of magnitude of systolic that \_archetype\_node\_id property is at0004**

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [September 28, 2017, 6:11pm UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/7 "2017-09-28T18:11:31Z")

</div>

I think I understand your question now, but to answer your question I would need to see the mapping for this index or better yet have a [curl recreation](https://www.elastic.co/help) of the problem? The query that you provided might work if you have a single nested level inside value. However, if you have multiple nested levels of documents you need to have multiple nested queries for each level as well.

---

<div class="post-metadata">

**Author:** ![yaser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaser/32/109240_2.png) [@yaser](https://discuss.elastic.co/u/yaser)\
**Post date:** [September 29, 2017, 3:21pm UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/8 "2017-09-29T15:21:53Z")

</div>

yes i know this work in single nested type but my question is ,can i separate this items from the \_archetype\_node\_id attribute ?

and this is my mapping

```
PUT my composition 
{
  "mappings": {
    "composition": { 
      "value": { "enabled": false }, 
      "properties": { 
        "value": { "type": "nested" }
      }
    }
}
}

```

**i have one value filed with nested type**

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [September 29, 2017, 5:54pm UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/9 "2017-09-29T17:54:06Z")

</div>

> [@yaser](#):
>
> can i separate this items from the \_archetype\_node\_id attribute ?

To do this you would need to have another nested field on the `value.composition.content.data.events.data.items` level.

---

<div class="post-metadata">

**Author:** ![yaser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaser/32/109240_2.png) [@yaser](https://discuss.elastic.co/u/yaser)\
**Post date:** [October 2, 2017, 4:37am UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/10 "2017-10-02T04:37:26Z")

</div>

you mean , there is no way to get items from items with \_archetype\_node\_id property?

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [October 3, 2017, 3:39pm UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/11 "2017-10-03T15:39:25Z")

</div>

There is, you just need to have nested `nested` object in your mapping.

---

<div class="post-metadata">

**Author:** ![yaser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaser/32/109240_2.png) [@yaser](https://discuss.elastic.co/u/yaser)\
**Post date:** [October 3, 2017, 6:00pm UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/12 "2017-10-03T18:00:04Z")

</div>

tank you so much .(sepas)

---

<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 31, 2017, 6:00pm UTC](https://discuss.elastic.co/t/how-can-i-run-this-query-just-for-find-first-item-in-a-path-with-4-items/101633/13 "2017-10-31T18:00:26Z")

</div>

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