在Elasticsearch查询中组合AND和OR的最佳方法

时间:2014-02-21 01:47:03

标签: elasticsearch

我的文档包含tags数组和city字段。我尝试在ES中查询这样的内容:

(javascript OR html OR css)和洛杉矶

最好的方法吗?
URI解决方案?

1 个答案:

答案 0 :(得分:1)

以下是获取(javascript OR html OR css) AND Los Angeles

的Elasticsearch查询
{
    "filter": {
        "and": {
           "filters": [
              {
                    "term": {
                       "city": "Los Angeles"
                    }
              },
              {
                "or": {
                   "filters": [
                      {
                          "terms": {
                             "tags": ["javascript","html","css"]
                          }
                      }
                   ]
                }
              }
           ]
        }
    }
}