Use the script feature in the stats facet -
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-stats-facet.html

The value computed can also be a script, using the value_script instead of
value_field, in which case the lang can control its language, and params allow
to provide custom parameters (as in other scripted components).




On Sun, Apr 13, 2014 at 2:51 PM, CC <[email protected]> wrote:

> Thank you very much for your reply. I tried using script fields, like
> this:
>
>   "query":{
>          "match_all": {}
>          },
>          "script_fields":{
>                 "test1":{
>                            "script": "_source.title.length()"}
>                            }
>         }
>
>  but what I get back from ES are only counts for the top 10 docs. How can
> I get values like max length, min length and average length for my title
> field? Thank you!
>
> On Saturday, April 12, 2014 2:50:04 PM UTC+2, vineeth mohan wrote:
>
>> Hello Cristina ,
>>
>> This is not possible using stat facet. It expect the field to be a number
>> and it calculates max/min etc based on its different values.
>>
>> A way to do this would be to add a new field while indexing which would
>> be the length of the title.
>> Then performing stats over it might work.
>>
>> There might be other solutions based on scripting , but i need to explore
>> ...
>>
>> Thanks
>>            Vineeth
>>
>>
>> On Sat, Apr 12, 2014 at 3:25 PM, Cristina Garbacea <[email protected]
>> > wrote:
>>
>>> I would like to retrieve statistical data about a string field like the
>>> min, max and average length (by counting the number of characters inside
>>> the string). I am using CURL to do this and I have what I have tried so far
>>>
>>>    "query":{
>>>          "match_all": {}
>>>     },
>>>    "facets":{
>>>          "stats":{
>>>                "statistical":{
>>>                      "field":"title"}
>>>                      }
>>>                 }
>>>
>>> returns me exception because the facet expects a number field. How can I
>>> achieve my goal? 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 [email protected].
>>>
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/elasticsearch/3c1a08f2-e467-47c3-a667-43837ac9b352%
>>> 40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/3c1a08f2-e467-47c3-a667-43837ac9b352%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/8bd3444c-5095-463c-adb9-60ea2eb42e57%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/8bd3444c-5095-463c-adb9-60ea2eb42e57%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3D-49cUg-nU9eyR6hkPd%2BisgR915hcH2ZuhtOC7Nm72JA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to