有没有办法结合Elasticsearch查询?

时间:2017-12-19 05:23:07

标签: elasticsearch elasticsearch-5

我有两个问题:

{
  "query": {
    "bool": {
      "must": [
        {"match": {"body": "a"}},
        {"match": {"body": "b"}},
        {"match": {"body": "c"}},
        {"match_phrase": {"body": "g h i"}},
        {"match_phrase": {"body": "j k l"}}
      ],
      "should": [
        {"match": {"body": "d"}},
        {"match": {"body": "e"}},
        {"match": {"body": "f"}}
      ],
      "must_not": [
        {"match": {"body": "m"}},
        {"match": {"body": "n"}}
      ]
    }
  }
}

{
  "query": {
    "bool": {
      "must": [
        {"match": {"body": "x"}},
        {"match": {"body": "y"}},
        {"match": {"body": "z"}},
        {"match_phrase": {"body": "new phrase"}},
        {"match_phrase": {"body": "second phrase"}}
      ],
      "should": [
        {"match": {"body": "T"}},
        {"match": {"body": "U"}},
        {"match": {"body": "V"}}
      ]
    }
  }
}

我已将这些jsons存储在db中,有时需要将它们组合在一起。有没有办法组合它们而无需从头开始重新创建json? 例如:

{'query': {'and': [query1, query2]}}

0 个答案:

没有答案