Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: Terms Stats Facet #705

Closed
kimchy opened this issue Feb 19, 2011 · 4 comments
Closed

Search: Terms Stats Facet #705

kimchy opened this issue Feb 19, 2011 · 4 comments

Comments

@kimchy
Copy link
Member

kimchy commented Feb 19, 2011

The terms_stats facet combines the terms and stats facet to group based on a key_field unique terms and compute stats (count, total, min, max) on another value field or script. For example:

{
    "query" : {
        "match_all" : {  }
    },
    "facets" : {
        "tag_price_stats" : {
            "terms_stats" : {
                "key_field" : "tag",
                "value_field" : "price"
            }
        }
    }
}

The size parameter controls how many facet entries will be returned. It defaults to 10. Setting it to 0 will return all terms matching the hits.

Ordering is done by setting order, with possible values of term, reverse_term, count, reverse_count, total, reverse_total, min, reverse_min, max, reverse_max. Defaults to term.

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

Note: It is expected that the will be a single value of the key field per doc, and one or multiple values of the value field.

@kimchy
Copy link
Member Author

kimchy commented Feb 19, 2011

Search: Terms Stats Facet, closed by 352cb74.

@deinspanjer
Copy link

wow. pivot tables for the win!

@itthuyloi
Copy link

In page: http://www.elasticsearch.org/guide/reference/api/search/facets/terms-stats-facet.html

"Note, the terms stats can work with multi valued key fields, or multi valued value fields, but not when both are multi valued (as ordering is not maintained)."

But how to build the query, I want to statistic of "hoursWorked" of a "Task log" have for {groupId and projectId}, please tell me!

I tried:


{
    "query": {
        "match_all": {
            
        }
    },
    "facets": {
        "hoursWorked_stats": {
            "terms_stats": {
                "key_field": ["groupId",
                "projectId"],
                "value_field": "hoursWorked",
                "size": 1000
            }
        }
    }
}

But it's not working!

@rbnacharya
Copy link

#6046

Count issue in terms stat facet. Please visit the issue..

mindw pushed a commit to mindw/elasticsearch that referenced this issue Sep 5, 2022
MPC-2400: remove AMS & related code from devops repo, part elastic#2

* remove AMS & mongodb and update rc.local for it

* gsed /d amd & mongodb out


Approved-by: Gabi Davar
Approved-by: Can Yildiz
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this issue Oct 2, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants