Elasticsearch |匹配多个短语

时间:2014-06-08 07:33:23

标签: elasticsearch match dsl querydsl

我试图创建一个查询,找到包含#breakingbad或“破坏”的所有状态

这是我到目前为止所做的,但根据意义显然是错误的:

{
   "query": {

      "match": {

         "_all": {

            "query": "breaking bad",
            "type": "phrase"
         }
      },
      "match": {
         "_all": {
             "query": "#breakingbad",
             "type": "phrase"
      }
   }
}

2 个答案:

答案 0 :(得分:3)

<强>解答:

{
    "query": {
        "bool": {
            "should": [
                {
                    "match": {
                        "message": {
                            "query": "breaking bad",
                            "type": "phrase"
                        }
                    }
                },
                {
                    "match": {
                        "message": "#poznasty"
                    }
                }
            ]
        }
    }
}

答案 1 :(得分:0)

为什么不使用multi_match

{
    "query" : {
        "multi_match" : {
            "fields" : ["name", "description"],
            "query" : "breaking bad",
            "type" : "phrase_prefix"
        }
    }
}

MultiMatchQueryBuilder builder = QueryBuilders.multiMatchQuery(query,
    "name", "description").type(MatchQueryBuilder.Type.PHRASE_PREFIX);