如何在elasticsearch查询中增加一些(但不是全部)术语

时间:2015-09-28 22:35:42

标签: python elasticsearch

我有一个单词列表,我想通过elasticsearch:

wordlist = ['my','list','of','words']

我想要做的就是提升'我的'而不是其他的话。我正在搜索的字段称为“文本”。

如果没有我实际可以运行的实现示例,我已经阅读了那些没有意义的文档。

以下是我认为很接近

{
          "query": {
            "custom_filters_score": {
              "query": { "match": { "_all": ' '.join(wordlist) } },
              "filters": [
                {
                  "filter": {
                    "term": {
                      "text": wordlist[0]
                    }
                  },
                  "boost": 2
                },
                {
                  "filter": {
                    "term": {
                      "text": wordlist[1]
                    }
                  },
                  "boost": 1.5
                }
              ],
            "score_mode" : "multiply"
            }
          }
        }

我已经在this博客帖子中对此进行了模拟,但我似乎无法弄清楚“......主要查询......”的含义是什么。

1 个答案:

答案 0 :(得分:1)

博客文章读起来很好但过时了 - 请参阅2015年的评论" ES 1.0+(即1.4,1.6,1.7)不再支持custom_script"。

像这样的function_score查询怎么样:

{
"query": {
    "function_score": {
        "query": {
            "match": {
                 "title": {      
                      "query": " ".join(wordlist),
                      "operator": "and"
                 }
            }
        },
        "functions": [
                {
                "filter": {"term": {"text": wordlist[0]}},
                "weight": "2.0"
                },
                {
                "filter": {"term": {"text": wordlist[1]}},
                "weight": "1.5"
                },
...
相关问题