1

我有两个文档存储在elasticsearch数据库中

一个是

{
   q :["python" , "foo"]
}

另一个是

{
   q :["python" , "moo","foo"]
}

现在我的问题是search记录哪些python在索引上0foo在索引上1如何实现这一点?我已经阅读了有关bool查询的信息,elasticsearch但不知道如何使用它,请帮助!

4

1 回答 1

1

你可以用脚本来做到这一点,试试这个

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "script": {
                "script": "_source.q[0] == \"python\" && _source.q[1] == \"foo\" "
              }
            }
          ]
        }
      }
    }
  }
}

虽然document fields被建议,因为它们被加载到内存中并且访问速度很快,但它们没有被排序。参考这个,因此在这种情况下我们需要使用_source

于 2016-01-07T04:27:13.133 回答