将范围查询添加到function_score前缀逻辑

时间:2018-01-17 21:08:25

标签: elasticsearch

我正在尝试将AND逻辑添加到下面的部分。

我想补充的是:

 "range" : {
            "rvolume_2017" : {
                "gte" : 5000,
                "lte" : 10000
            }
        }

这是有效的,需要扩展

{
  "query": {
    "function_score": {
       "query": {
          "match_phrase_prefix": {
             "keyword.autocomplete": {
                "query": "samsung case"
                ,"analyzer": "standard"
                , "max_expansions": 500
               }
          }
       },
        "script_score" : {
                "script" : {
                  "source": "doc['rvolume_2017'].value+doc['cpc_2017'].value"
                }
            }
    }
  }
}

我尝试打包到bool查询但我得到了[bool] query does not support [match_phrase_prefix]

1 个答案:

答案 0 :(得分:1)

{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
            {
              "match_phrase_prefix": {
                "keyword.autocomplete": {
                  "query": "samsung case",
                  "analyzer": "standard",
                  "max_expansions": 500
                }
              }
            },
            {
              "range": {
                "rvolume_2017": {
                  "gte": 5000,
                  "lte": 10000
                }
              }
            }
          ]
        }
      },
      "script_score": {
        "script": {
          "source": "doc['rvolume_2017'].value+doc['cpc_2017'].value"
        }
      }
    }
  }
}