'Multiple wildcards in one query in elasticsearch
curl localhost:9200/tweet/posts/_search -d '{
"query": {
"and": [
{
"wildcard": {
"_all": "*pet*"
}
},
{
"wildcard": {
"_all": "*rom*"
}
}
]
}
}'
This gives me a parse exception. I want to run a MySQL like(%test%) type query with an AND condition. Is there any other good way to do in elasticsearch.
Solution 1:[1]
Maybe something like this?
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"_all": {
"value": "*pet*"
}
}
},
{
"wildcard": {
"_all": {
"value": "*rom*"
}
}
}
]
}
}
}
Solution 2:[2]
dis_max query can support wildcard queries not a bool. Please take a look here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html I would write something like this:
{
"query": {
"dis_max": {
"queries": [
{"wildcard": {
"_all": {"value" : "*pet*"}
}},
{"wildcard": {
"_all": {"value" : "*rom*"}
}}
]
}
}
}
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 | Alcanzar |
| Solution 2 | MichalT |
