# Facet Filter : by index?

**URL:** <https://discuss.elastic.co/t/facet-filter-by-index/14581>\
**Category:** Elasticsearch\
**Created:** [November 25, 2013, 5:48pm UTC](https://discuss.elastic.co/t/facet-filter-by-index/14581 "2013-11-25T17:48:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Conlin](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mark\_Conlin](https://discuss.elastic.co/u/Mark_Conlin)\
**Post date:** [November 25, 2013, 5:48pm UTC](https://discuss.elastic.co/t/facet-filter-by-index/14581/1 "2013-11-25T17:48:31Z")

</div>

I would like to do some faceting on my data set, but want results per index  
in one query.  
I am aware I could simply query N indices individual to gather the same  
results, but want to make a single round trip not N.

Is this possible?

I tried to construct a facet filter on \_index, this did not work.

{  
"query": {  
"filtered": {  
"query": { "match\_all": {} }  
}  
},  
"facets": {  
"f1": {  
"facet\_filter": {  
"and": [  
{  
"exists": { "field": "myfield"}  
},  
{  
"term": { "\_index": "sampleset\_1"}  
}  
]  
},  
"terms": { "field": "myfield" }  
}  
},  
"size": 0  
}

A base query against \_index doesnt work either

{  
"query" : {  
"match": {"\_index":"sample\_1"}  
}  
}

Does this mean that \_index is not available as a query or facet field?

Thanks

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Mark\_Conlin](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mark\_Conlin](https://discuss.elastic.co/u/Mark_Conlin)\
**Post date:** [November 25, 2013, 7:01pm UTC](https://discuss.elastic.co/t/facet-filter-by-index/14581/2 "2013-11-25T19:01:53Z")

</div>

I also tried an indices query, but they dont support facets...

{  
"query" : {  
"indices" :  
{  
"indices":["sample\_1"],  
"query" : {  
"match\_all": {}  
},  
"facets": {  
"f1": {  
"terms": {  
"field": "myfield",  
"size": 100  
}  
}  
}  
}  
}  
}

On Monday, November 25, 2013 12:48:31 PM UTC-5, Mark Conlin wrote:

> I would like to do some faceting on my data set, but want results per  
> index in one query.  
> I am aware I could simply query N indices individual to gather the same  
> results, but want to make a single round trip not N.
> 
> Is this possible?
> 
> I tried to construct a facet filter on \_index, this did not work.
> 
> {  
> "query": {  
> "filtered": {  
> "query": { "match\_all": {} }  
> }  
> },  
> "facets": {  
> "f1": {  
> "facet\_filter": {  
> "and": [  
> {  
> "exists": { "field": "myfield"}  
> },  
> {  
> "term": { "\_index": "sampleset\_1"}  
> }  
> ]  
> },  
> "terms": { "field": "myfield" }  
> }  
> },  
> "size": 0  
> }
> 
> A base query against \_index doesnt work either
> 
> {  
> "query" : {  
> "match": {"\_index":"sample\_1"}  
> }  
> }
> 
> Does this mean that \_index is not available as a query or facet field?
> 
> Thanks

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 26, 2013, 5:44pm UTC](https://discuss.elastic.co/t/facet-filter-by-index/14581/3 "2013-11-26T17:44:26Z")

</div>

I have never tried, but did you enable the index field?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

From what I can understand by glancing quickly at the code, the field will  
not be created until it is enabled:  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java?source=c#L184-L189](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java?source=c#L184-L189)

Cheers,

Ivan

On Mon, Nov 25, 2013 at 11:01 AM, Mark Conlin [mark.conlin@gmail.com](mailto:mark.conlin@gmail.com) wrote:

> I also tried an indices query, but they dont support facets...
> 
> {  
> "query" : {  
> "indices" :  
> {  
> "indices":["sample\_1"],
> 
> ```
> "query" : {
> "match_all": {}
> },
> "facets": {
> "f1": {
> 
> "terms": {
> "field": "myfield",
> "size": 100
> }
> }
> }
> }
> }
> 
> ```
> 
> }
> 
> On Monday, November 25, 2013 12:48:31 PM UTC-5, Mark Conlin wrote:
> 
> > I would like to do some faceting on my data set, but want results per  
> > index in one query.  
> > I am aware I could simply query N indices individual to gather the same  
> > results, but want to make a single round trip not N.
> > 
> > Is this possible?
> > 
> > I tried to construct a facet filter on \_index, this did not work.
> > 
> > {  
> > "query": {  
> > "filtered": {  
> > "query": { "match\_all": {} }  
> > }  
> > },  
> > "facets": {  
> > "f1": {  
> > "facet\_filter": {  
> > "and": [  
> > {  
> > "exists": { "field": "myfield"}  
> > },  
> > {  
> > "term": { "\_index": "sampleset\_1"}  
> > }  
> > ]  
> > },  
> > "terms": { "field": "myfield" }  
> > }  
> > },  
> > "size": 0  
> > }
> > 
> > A base query against \_index doesnt work either
> > 
> > {  
> > "query" : {  
> > "match": {"\_index":"sample\_1"}  
> > }  
> > }
> > 
> > Does this mean that \_index is not available as a query or facet field?
> > 
> > Thanks
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CALY%3DcQCE8Ap%3D42nd%2Bkv-VPJVtzsPOViF7NirHspTCnEc0f6LPg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCE8Ap%3D42nd%2Bkv-VPJVtzsPOViF7NirHspTCnEc0f6LPg%40mail.gmail.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, 2:04am UTC](https://discuss.elastic.co/t/facet-filter-by-index/14581/4 "2017-07-06T02:04:45Z")

</div>


