Elasticsearch : match query with empty string as a value for field

≯℡__Kan透↙ 提交于 2021-01-28 14:45:00

问题


I have a match query that query the fields title1, title2 with param that contains sometimes an empty string.

When the value of the param is empty the query returns no results which is normal.

My question is if it possible to make in one single query , this : if the param is not an empty string query all documents, otherwise do a normal multi_match query .

The pseudo code of my query:

{
 "query" : {
     "bool" : {
       "must" : {
          "multi_match" : {
                "query":    param, 
                "fields": [ "title1", "title2" ] 
              },
           "match" : {
                 "query": { "publish" : true}
            }

      }
    }
  }
}

Thanks,

来源:https://stackoverflow.com/questions/30697557/elasticsearch-match-query-with-empty-string-as-a-value-for-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!