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

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

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!

1 Like

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 .

I want to filter the range of magnitude of systolic that _archetype_node_id property is at0004

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 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.

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

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

1 Like

you mean , there is no way to get items from items with _archetype_node_id property?

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

tank you so much .(sepas)

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