Range Facet doesn't work


(Guram Kajaia) #1

Hello guys.
I'm playing with range facet but it's not working for me.
I'm running query as mentioned in guide :
http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html
Here is query

{
"query" : {
"match_all" : {}
},
"facets" : {
"range1" : {
"range" : {
"my_field" : [
{ "to" : 50 },
{ "from" : 20, "to" : 70 },
{ "from" : 70, "to" : 120 },
{ "from" : 150 }
]
}
}
}
}

And here is returned error:

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], total failure; shardFailures {[QKlvaSVSTU-fJtjD0R4_9Q][deals][4]:
QueryPhaseExecutionException[[deals][4]:
query[ConstantScore(NotDeleted(:))],from[0],size[10]: Query Failed
[Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData
cannot be cast to org.elasticsearch.index.field.data.NumericFieldData];
}{[QKlvaSVSTU-fJtjD0R4_9Q][deals][1]:
QueryPhaseExecutionException[[deals][1]:
query[ConstantScore(NotDeleted(:))],from[0],size[10]: Query Failed
[Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData
cannot be cast to org.elasticsearch.index.field.data.NumericFieldData]; }]",
"status": 500
}

can anyone help me ?

Thanks.


(Clinton Gormley) #2
    ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData cannot be cast to org.elasticsearch.index.field.data.NumericFieldData]; 

Your 'myfield' is mapped as a string, not as a number.

clint


(Guram Kajaia) #3

Thanks.
But range facet works only with Integer type ? not floats ?

On Fri, Jul 27, 2012 at 6:24 PM, Clinton Gormley clint@traveljury.comwrote:

ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData
cannot be cast to org.elasticsearch.index.field.data.NumericFieldData];

Your 'myfield' is mapped as a string, not as a number.

clint


(Clinton Gormley) #4

On Fri, 2012-07-27 at 19:00 +0400, Guram Kajaia wrote:

Thanks.
But range facet works only with Integer type ? not floats ?

It works with floats, but your field is a string

On Fri, Jul 27, 2012 at 6:24 PM, Clinton Gormley
clint@traveljury.com wrote:
>
ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData cannot be cast to org.elasticsearch.index.field.data.NumericFieldData];

    Your 'myfield' is mapped as a string, not as a number.
    
    clint

(Guram Kajaia) #5

On Jul 27, 2012 7:05 PM, "Clinton Gormley" clint@traveljury.com wrote:

On Fri, 2012-07-27 at 19:00 +0400, Guram Kajaia wrote:

Thanks.
But range facet works only with Integer type ? not floats ?

It works with floats, but your field is a string

On Fri, Jul 27, 2012 at 6:24 PM, Clinton Gormley
clint@traveljury.com wrote:
>

ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData
cannot be cast to org.elasticsearch.index.field.data.NumericFieldData];

    Your 'myfield' is mapped as a string, not as a number.

    clint

(Guram Kajaia) #6

Thanks i'll try
On Jul 27, 2012 7:05 PM, "Clinton Gormley" clint@traveljury.com wrote:

On Fri, 2012-07-27 at 19:00 +0400, Guram Kajaia wrote:

Thanks.
But range facet works only with Integer type ? not floats ?

It works with floats, but your field is a string

On Fri, Jul 27, 2012 at 6:24 PM, Clinton Gormley
clint@traveljury.com wrote:
>

ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData
cannot be cast to org.elasticsearch.index.field.data.NumericFieldData];

    Your 'myfield' is mapped as a string, not as a number.

    clint

(Guram Kajaia) #7

So it works with floats too ( when I created index with curl without
specifying number_of_shards and number_of_replicas I got error when i was
using range facet )
So range facet now works well but returned documents doesn't matches facet
parameters.
Here is query

{

"query": {
"match_all": {}
},
"facets": {
"range1": {
"range": {
"field": "deal_price",
"ranges": [
{
"from": 4,
"to": 7
}
]
}
}
}
}

count that facet returns is 3 but i'm getting more then 3 results in "hits"
are query and facets depended to each other? or they work separately ?

On Fri, Jul 27, 2012 at 9:29 AM, Guram Kajaia guram.kajaia@gmail.comwrote:

Thanks i'll try
On Jul 27, 2012 7:05 PM, "Clinton Gormley" clint@traveljury.com wrote:

On Fri, 2012-07-27 at 19:00 +0400, Guram Kajaia wrote:

Thanks.
But range facet works only with Integer type ? not floats ?

It works with floats, but your field is a string

On Fri, Jul 27, 2012 at 6:24 PM, Clinton Gormley
clint@traveljury.com wrote:
>

ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData
cannot be cast to org.elasticsearch.index.field.data.NumericFieldData];

    Your 'myfield' is mapped as a string, not as a number.

    clint

(Clinton Gormley) #8

Hi Guram

On Fri, 2012-07-27 at 15:11 -0700, Guram Kajaia wrote:

So it works with floats too ( when I created index with curl without
specifying number_of_shards and number_of_replicas I got error when i
was using range facet )

That was coincidental :slight_smile: The problem you were having (I think) is that
you were creating the field mapping automatically by indexing a
document, but instead of indexing (eg) { myfield: 123 } you're indexing
{ myfield: "123" }, which means "this is a string".

So range facet now works well but returned documents doesn't matches
facet parameters.
Here is query

    {
      "query": {
        "match_all": {}
      },
      "facets": {
        "range1": {
          "range": {
            "field": "deal_price",
            "ranges": [
              {
                "from": 4,
                "to": 7
              }
            ]
          }
        }
      }
    }

count that facet returns is 3 but i'm getting more then 3 results in
"hits"
are query and facets depended to each other? or they work separately ?

Facets are calculated based on the results returns from the query. So
the facet doesn't limit the query results at all.

clint

On Fri, Jul 27, 2012 at 9:29 AM, Guram Kajaia guram.kajaia@gmail.com
wrote:
Thanks i'll try

    On Jul 27, 2012 7:05 PM, "Clinton Gormley"
    <clint@traveljury.com> wrote:
            On Fri, 2012-07-27 at 19:00 +0400, Guram Kajaia wrote:
            > Thanks.
            > But range facet works only with Integer type ? not
            floats ?
            
            It works with floats, but your field is a string
            
            >
            > On Fri, Jul 27, 2012 at 6:24 PM, Clinton Gormley
            > <clint@traveljury.com> wrote:
            >         >
            >
            ClassCastException[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData cannot be cast to org.elasticsearch.index.field.data.NumericFieldData];
            >
            >
            >         Your 'myfield' is mapped as a string, not as
            a number.
            >
            >         clint
            >
            >

(system) #9