# Facet query and Exceptions

**URL:** <https://discuss.elastic.co/t/facet-query-and-exceptions/6931>\
**Category:** Elasticsearch\
**Created:** [March 7, 2012, 2:45pm UTC](https://discuss.elastic.co/t/facet-query-and-exceptions/6931 "2012-03-07T14:45:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pulkitsinghal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pulkitsinghal/32/802_2.png) [@pulkitsinghal](https://discuss.elastic.co/u/pulkitsinghal)\
**Post date:** [March 7, 2012, 2:45pm UTC](https://discuss.elastic.co/t/facet-query-and-exceptions/6931/1 "2012-03-07T14:45:30Z")

</div>

When testing my query using ES-Head, I receive the following exception  
on the server side:

Caused by:  
org.elasticsearch.search.facet.FacetPhaseExecutionException: Facet  
[range1]: No mapping found for key\_field [regularPrice]

Other than indexing the data and forming a query based on:  
[http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html)  
Are there any other steps involved that I may be missing?

{  
"fields": [  
"name",  
"upc",  
"salePrice",  
"regularPrice"  
],  
"query": {  
"query\_string": {  
"fields": [  
"name"  
],  
"query": "+camera +laptop",  
"use\_dis\_max": true  
}  
},  
"facets": {  
"range1": {  
"range": {  
"regularPrice": [  
{  
"to": 50  
},  
{  
"from": 20,  
"to": 70  
},  
{  
"from": 70,  
"to": 120  
},  
{  
"from": 150  
}  
]  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 7, 2012, 9:08pm UTC](https://discuss.elastic.co/t/facet-query-and-exceptions/6931/2 "2012-03-07T21:08:34Z")

</div>

You are sending the wrong format for the range facet, see the correct structure here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html).

On Wednesday, March 7, 2012 at 4:45 PM, pulkitsinghal wrote:

> {  
> "fields": [  
> "name",  
> "upc",  
> "salePrice",  
> "regularPrice"  
> ],  
> "query": {  
> "query\_string": {  
> "fields": [  
> "name"  
> ],  
> "query": "+camera +laptop",  
> "use\_dis\_max": true  
> }  
> },  
> "facets": {  
> "range1": {  
> "range": {  
> "regularPrice": [  
> {  
> "to": 50  
> },  
> {  
> "from": 20,  
> "to": 70  
> },  
> {  
> "from": 70,  
> "to": 120  
> },  
> {  
> "from": 150  
> }  
> ]  
> }  
> }  
> }  
> }

---

<div class="post-metadata">

**Author:** ![pulkitsinghal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pulkitsinghal/32/802_2.png) [@pulkitsinghal](https://discuss.elastic.co/u/pulkitsinghal)\
**Post date:** [March 8, 2012, 3:37am UTC](https://discuss.elastic.co/t/facet-query-and-exceptions/6931/3 "2012-03-08T03:37:58Z")

</div>

Thanks for the input Shay but as far as I'm aware, the format for the  
facets is completely copied pasted out of the link you gave as it was my  
starting point. Obviously I'm missing something, can you please elaborate a  
bit more?

On Wed, Mar 7, 2012 at 3:08 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> You are sending the wrong format for the range facet, see the correct  
> structure here:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html)  
> .
> 
> On Wednesday, March 7, 2012 at 4:45 PM, pulkitsinghal wrote:
> 
> {  
> "fields": [  
> "name",  
> "upc",  
> "salePrice",  
> "regularPrice"  
> ],  
> "query": {  
> "query\_string": {  
> "fields": [  
> "name"  
> ],  
> "query": "+camera +laptop",  
> "use\_dis\_max": true  
> }  
> },  
> "facets": {  
> "range1": {  
> "range": {  
> "regularPrice": [  
> {  
> "to": 50  
> },  
> {  
> "from": 20,  
> "to": 70  
> },  
> {  
> "from": 70,  
> "to": 120  
> },  
> {  
> "from": 150  
> }  
> ]  
> }  
> }  
> }  
> }

---

<div class="post-metadata">

**Author:** ![pulkitsinghal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pulkitsinghal/32/802_2.png) [@pulkitsinghal](https://discuss.elastic.co/u/pulkitsinghal)\
**Post date:** [March 8, 2012, 4:11am UTC](https://discuss.elastic.co/t/facet-query-and-exceptions/6931/4 "2012-03-08T04:11:20Z")

</div>

I've found out that the query that I initially posted never had a problem  
to begin with, apparently instead of POST-ing directly against  
[http://localhost:9200/my\_index/\_search/](http://localhost:9200/my_index/_search/) I had been posting against  
[http://localhost:9200/\_search/](http://localhost:9200/_search/) which was the real source of the exception.

I only have two indices, one is "my\_index" and another is the "\_river" that  
helped put the data in the my\_index together. So my _guess_ is that the  
exception is really stemming from the \_river index which ofcourse does not  
have any mapping for the regularPrice field.

What I personally find to be strange is that until I had not run the query  
against anything other than [http://localhost:9200/\_search/](http://localhost:9200/_search/) ... there  
weren't any results being returned at all. But after I ran the query  
against [http://localhost:9200/my\_index/\_search/](http://localhost:9200/my_index/_search/) just once ... even POST-ing  
back again to the original [http://localhost:9200/\_search/](http://localhost:9200/_search/) started providing  
results from the my\_index and still showing the exception from the \_river  
index in the logs.

Now if this is a given in terms of normal behavior, then please feel free  
to call it out and let me know.

Thanks,

- Pulkit

On Wed, Mar 7, 2012 at 9:37 PM, Pulkit Singhal [pulkitsinghal@gmail.com](mailto:pulkitsinghal@gmail.com)wrote:

> Thanks for the input Shay but as far as I'm aware, the format for the  
> facets is completely copied pasted out of the link you gave as it was my  
> starting point. Obviously I'm missing something, can you please elaborate a  
> bit more?
> 
> On Wed, Mar 7, 2012 at 3:08 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > You are sending the wrong format for the range facet, see the correct  
> > structure here:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html)  
> > .
> > 
> > On Wednesday, March 7, 2012 at 4:45 PM, pulkitsinghal wrote:
> > 
> > {  
> > "fields": [  
> > "name",  
> > "upc",  
> > "salePrice",  
> > "regularPrice"  
> > ],  
> > "query": {  
> > "query\_string": {  
> > "fields": [  
> > "name"  
> > ],  
> > "query": "+camera +laptop",  
> > "use\_dis\_max": true  
> > }  
> > },  
> > "facets": {  
> > "range1": {  
> > "range": {  
> > "regularPrice": [  
> > {  
> > "to": 50  
> > },  
> > {  
> > "from": 20,  
> > "to": 70  
> > },  
> > {  
> > "from": 70,  
> > "to": 120  
> > },  
> > {  
> > "from": 150  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }

---

<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, 3:36am UTC](https://discuss.elastic.co/t/facet-query-and-exceptions/6931/5 "2017-07-06T03:36:43Z")

</div>


