# Ability to search accross 'types' in the same index, with different search parameters yet applying the same size and from values, in a single search query

**URL:** <https://discuss.elastic.co/t/ability-to-search-accross-types-in-the-same-index-with-different-search-parameters-yet-applying-the-same-size-and-from-values-in-a-single-search-query/19455>\
**Category:** Elasticsearch\
**Created:** [August 26, 2014, 7:51am UTC](https://discuss.elastic.co/t/ability-to-search-accross-types-in-the-same-index-with-different-search-parameters-yet-applying-the-same-size-and-from-values-in-a-single-search-query/19455 "2014-08-26T07:51:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ajinkya\_Apte](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Ajinkya\_Apte](https://discuss.elastic.co/u/Ajinkya_Apte)\
**Post date:** [August 26, 2014, 7:51am UTC](https://discuss.elastic.co/t/ability-to-search-accross-types-in-the-same-index-with-different-search-parameters-yet-applying-the-same-size-and-from-values-in-a-single-search-query/19455/1 "2014-08-26T07:51:22Z")

</div>

Hello,  
Examples of some documents:

POST /test-index/test-type-1/doc-1  
{  
"text" : "Some text",  
"status" : 1  
}

POST /test-index/test-type-2/doc-1  
{  
"text" : "Some new text",  
"status" : 1  
}

POST /test-index/test-type-2/doc-2  
{  
"text" : "Some even new text",  
"status" : 2  
}

Is there a single query I can use so that I can get all the documents that  
are of 'status'=1 in 'type'='test-type-1' and 'status'=2 in  
'type'='test-type-2' applying the same 'size' and 'from' params? As of  
right now I am running two different queries and then I am trying to merge  
them programatically. Any better way you recommend?

AJ

--  
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/7f6bac9f-8fc3-4886-8a70-4dac81424073%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7f6bac9f-8fc3-4886-8a70-4dac81424073%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 26, 2014, 12:38pm UTC](https://discuss.elastic.co/t/ability-to-search-accross-types-in-the-same-index-with-different-search-parameters-yet-applying-the-same-size-and-from-values-in-a-single-search-query/19455/2 "2014-08-26T12:38:04Z")

</div>

Hello AJ ,

You can do this as follows

{  
"query\_string" : {  
"query" : "test-type1.status:1 || test-type2.status:2"  
}

But then there is a bug associated with a corner condition of this -

> <https://github.com/elastic/elasticsearch/issues/4081>
>
> As far as I understand it, fields are resolved on a \_first found\_ basis. So give…n the following documents:
> 
> \`\`\`
> PUT /index/foo/1
> {
> "count": 1,
> "foo": {
> "count": 1
> }
> }
> 
> PUT /index/bar/2
> {
> "count": 1,
> "foo": {
> "count": 1
> }
> }
> \`\`\`
> 
> .... the field \`foo.count\` could resolve to \`foo.count\`, \`foo.foo.count\`, or \`bar.foo.count\`, depending on which is found first.
> 
> Field resolution should be unambiguous. Field names should be grouped by type and sorted in descending order by number of \`.\`. So the above mappings should result in:
> 
> \`\`\`
> bar:
> foo.count
> count
> 
> foo:
> foo.count
> count
> \`\`\`
> 
> Then if no type is specified (or multiple types are specified), go through the groups in alphabetical order.
> 
> This would result in the following resolutions:
> 
> \`\`\`
> foo.foo.count =\> (foo) foo.count
> foo.count =\> (foo) count
> count =\> (bar) count
> \*.foo.count =\> (bar) foo.count
> \*.count =\> (bar) count
> \*.\*.count =\> (bar) foo.count
> \`\`\`

So be a bit careful.

Thanks  
Vineeth

Thanks  
Vineeth

}

On Tue, Aug 26, 2014 at 1:21 PM, Ajinkya Apte [ajinx14@gmail.com](mailto:ajinx14@gmail.com) wrote:

> Hello,  
> Examples of some documents:
> 
> POST /test-index/test-type-1/doc-1  
> {  
> "text" : "Some text",  
> "status" : 1  
> }
> 
> POST /test-index/test-type-2/doc-1  
> {  
> "text" : "Some new text",  
> "status" : 1  
> }
> 
> POST /test-index/test-type-2/doc-2  
> {  
> "text" : "Some even new text",  
> "status" : 2  
> }
> 
> Is there a single query I can use so that I can get all the documents that  
> are of 'status'=1 in 'type'='test-type-1' and 'status'=2 in  
> 'type'='test-type-2' applying the same 'size' and 'from' params? As of  
> right now I am running two different queries and then I am trying to merge  
> them programatically. Any better way you recommend?
> 
> AJ
> 
> --  
> 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/7f6bac9f-8fc3-4886-8a70-4dac81424073%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7f6bac9f-8fc3-4886-8a70-4dac81424073%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/7f6bac9f-8fc3-4886-8a70-4dac81424073%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/7f6bac9f-8fc3-4886-8a70-4dac81424073%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5nkrc8beGyi-tLgox4Ec25H%2BUftBTy1-Q7xbwXOP4RMVg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nkrc8beGyi-tLgox4Ec25H%2BUftBTy1-Q7xbwXOP4RMVg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:06am UTC](https://discuss.elastic.co/t/ability-to-search-accross-types-in-the-same-index-with-different-search-parameters-yet-applying-the-same-size-and-from-values-in-a-single-search-query/19455/3 "2017-07-06T01:06:29Z")

</div>


