# Embedded query

**URL:** <https://discuss.elastic.co/t/embedded-query/15254>\
**Category:** Elasticsearch\
**Created:** [January 15, 2014, 7:01pm UTC](https://discuss.elastic.co/t/embedded-query/15254 "2014-01-15T19:01:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_Schmidt](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@Thiago\_Schmidt](https://discuss.elastic.co/u/Thiago_Schmidt)\
**Post date:** [January 15, 2014, 7:01pm UTC](https://discuss.elastic.co/t/embedded-query/15254/1 "2014-01-15T19:01:33Z")

</div>

Is it possible to perform the query as embedded type and retrieves it as  
nested type? I'll explain. I have the following mapping.

{  
"page" : {  
"properties" : {  
"number" : {"type" : "integer", "store" : "yes", "index":"analyzed"},  
"file\_name" : {"type" : "string", "store" : "yes", "index":"no"},  
"line" : {  
"type" : "object",  
"properties" : {  
"number" : {"type" : "integer", "store" : "yes", "index":"not\_analyzed"},  
"text" : {"type" : "string", "store" : "no", "index":"analyzed"}  
}  
}  
}  
}

}

The data.

{  
"page" : {  
"id" : "1",  
"number" : 1,  
"file\_name" : "page1.jpg",  
"line" : [ {  
"number" : 1,  
"text" : "Informally, an object’s state is its data, stored in state  
variables such as instance"  
} ,  
{  
"number" : 2,  
"text" : "or static fields. An object’s state may include fields from  
other, dependent objects"  
},  
{  
"number" : 3,  
"text" : "a HashMap’s state is partially stored in the HashMap object  
itself, but also in many"  
},  
{  
"number" : 4,  
"text" : "Map.Entry objects. An object’s state encompasses any data  
that can affect its"  
}]  
}  
}

I run the query above :

{  
"query": {  
"bool" : {  
"must" : [{"term": {"text": "Informally," } } ,  
{"term": {"text": "state" } } ]  
}  
}  
}

The document "page" with id 1, will be returned from my query, because the  
word "informally" and "state" are in the same document page (line 1 and  
line 3). It's perfect, embedded objects work this way. And my objective is  
really get the mandatory words within the document page. If the page  
document was a nested type, query would not work in the desired manner.

{  
"took": 5,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 0.23977767,  
"hits": [  
{  
"\_index": "docman",  
"\_type": "page",  
"\_id": "1",  
"\_score": 0.23977767,  
"\_source": {  
"page": {  
"id": "1",  
"number": 1,  
"file\_name": "page1.jpg",  
"line": [  
{  
"number": 1,  
"text": "Informally, an object’s state is its data,  
stored in state variables such as instance"  
},  
{  
"number": 2,  
"text": "or static fields. An object’s state may  
include fields from other, dependent objects"  
},  
{  
"number": 3,  
"text": "a HashMap’s state is partially stored in  
the HashMap object itself, but also in many"  
},  
{  
"number": 4,  
"text": "Map.Entry objects. An object’s state  
encompasses any data that can affect its"  
}  
]  
}  
}  
}  
]  
}  
}

in my scenario, the problem is, I do not like that the result of my query  
to bring the lines 2 and 3, since they do not have the words searched.  
That's why at first I said "perform the query as embedded type and  
retrieves it as nested type." Is there any way to do this?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b5978770-41ae-48a8-b093-9d32e9211a16%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b5978770-41ae-48a8-b093-9d32e9211a16%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 1:56am UTC](https://discuss.elastic.co/t/embedded-query/15254/2 "2017-07-06T01:56:40Z")

</div>

Closed on July 6, 2017, 1:56am UTC


