Skip to content

Instantly share code, notes, and snippets.

@sajidzaman
Last active August 16, 2017 13:13
Show Gist options
  • Save sajidzaman/341a520efccde2523e2238c2e62a2396 to your computer and use it in GitHub Desktop.
Save sajidzaman/341a520efccde2523e2238c2e62a2396 to your computer and use it in GitHub Desktop.
Elastic search Filters
GET courses/_search
{
"query" :{
"bool":{
"filter" :{
"match": {"name": "accounting"}
}
}
}
}
Filters does not do relevancy scoring
Primarilary used for fetching the data.
Filters are cached.
GET courses/_search
{
"query" :{
"bool":{
"filter" :{
"bool":{
"must":[
{"match": {"name": "accounting"}}
]
}
},
"must": [
{"match": {"room":"e3"}}
]
}
}
}
GET courses/_search
{
"query" :{
"bool":{
"filter" :{
"bool":{
"must":[
{"match": {"name": "accounting"}},
{"match": {"professor.name": "bill"}}
]
}
}
}
}
}
Use of Must in filter
GET courses/_search
{
"query" :{
"bool":{
"filter" :{
"bool":{
"must":[
{"match": {"name": "accounting"}},
{"match": {"professor.name": "bill"}}
],
"must_not": [
{"match": {"room":"e7"}}
]
}
}
}
}
}
GET courses/_search
{
"query" :{
"bool":{
"filter" :{
"bool":{
"must":[
{"match": {"name": "accounting"}}
]
}
},
"should": [
{"match": {"room":"e3"}}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment