'Matching query with multiple values in Elasticsearch-dsl
I am trying to write a query, In which multiple values should get matched with the field.
In the example, I am trying to get results from all months with the matching field in the query. What I don't know is, how to write this query in dsl ?
months = [2,3,4]
client = Elasticsearch()
s = Search(using=client, index="namco_revenuestream")
s = s.query("match", month_period=months)
elasticsearch">
elasticsearchelasticsearch-dsl">
elasticsearch-dslelasticsearch-dsl-py">
elasticsearch-dsl-py
Solution 1:[1]
You can use terms query instead of match query as below:
{
"query": {
"terms": {
"month_period": [2,3,4]
}
}
}
EDIT: Query using match
{
"query": {
"match": {
"month_period": {
"query": "2 3 4",
"analyzer": "standard"
}
}
}
}
Solution 2:[2]
q1 = Q("terms", phone=items)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Dave |
