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: Allow to pass a search filter, applying only on the query (and not on facets for example) #650

Closed
kimchy opened this issue Jan 26, 2011 · 1 comment

Comments

@kimchy
Copy link
Member

kimchy commented Jan 26, 2011

When doing things like facet navigation, sometimes only the hits are needed to be filtered by the chosen facet, and all the facets should continue to be calculated based on the original query. The new filter element within the search request can be used to accomplish it.

For example, lets create two tweets, with two different tags:

curl -XPUT 'localhost:9200/twitter/tweet/1' -d '
{
    "message" : "something blue",
    "tag" : "blue"
}
'

curl -XPUT 'localhost:9200/twitter/tweet/2' -d '
{
    "message" : "something green",
    "tag" : "green"
}
'

curl -XPOST 'localhost:9200/_refresh'

We can now search for something, and have a terms facet.

curl -XPOST 'localhost:9200/twitter/_search?pretty=true' -d '
{
    "query" : {
        "term" : { "message" : "something" }
    },
    "facets" : {
        "tag" : {
            "terms" : { "field" : "tag" }
        }
    }
}
'

We get two hits, and the relevant facets with a count of 1 for both green and blue. Now, lets say the green facet is chosen, we can simply add a filter for it:

curl -XPOST 'localhost:9200/twitter/_search?pretty=true' -d '
{
    "query" : {
        "term" : { "message" : "something" }
    },
    "filter" : {
        "term" : { "tag" : "green" }
    },
    "facets" : {
        "tag" : {
            "terms" : { "field" : "tag" }
        }
    }
}
'

And now, we get only 1 hit back, but the facets remain the same.

Note, if additional filters is required on specific facets, they can be added as a facet_filter to the relevant facets.

@kimchy
Copy link
Member Author

kimchy commented Jan 26, 2011

Search: Allow to pass a search filter, applying only on the query (and not on facets for example), closed by 5a4686a.

tallpsmith pushed a commit to tallpsmith/elasticsearch that referenced this issue May 5, 2011
emilykmarx pushed a commit to emilykmarx/elasticsearch that referenced this issue Dec 26, 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

1 participant