问题
I have to check if a field matches a specific text OR is empty. Is it possible to do that?
Thank you.
回答1:
You can achieve this by using the missing filter. For example:
POST /my_index/items
{
"field1": "value1"
}
POST /my_index/items
{
"field1": "value2"
}
POST /my_index/items
{
"field1": ""
}
POST /my_index/_refresh
POST /my_index/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"or": {
"filters": [
{
"term": {
"field1": "value1"
}
},
{
"missing": {
"field": "field1"
}
}
]
}
}
}
}
}
来源:https://stackoverflow.com/questions/22635404/elasticsearch-match-string-or-empty-value