本文介绍了elasticsearch 排除具有值的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何执行搜索排除字段具有特定值的结果?

How can i perform a search excluding results where a field has a specific value?

我有一个 Reddit 评论数据库,我想找到比特币提及,但排除比特币 subreddit.

I have a database of Reddit comments and i want to find Bitcoin mentions, but exclude the bitcoin subreddit.

curl -s -XGET 'http://localhost:9200/_search?pretty=true&size=100' -d '
{
    "filtered": {
        "query" : {
            "match": {
                "body": "bitcoin"
            }
        },
        "filter": {
            "not": {
                "term": {
                    "subreddit": "bitcoin"
                }
            }
        }

    }
}'

错误太久不能在这里发帖了.https://gist.github.com/kylelk/feca416156712eebad3e

The error is to long to post here. https://gist.github.com/kylelk/feca416156712eebad3e

推荐答案

愚蠢的错误,

您必须在 query 中包含过滤后的查询.这里是修改

You have to include filtered query inside query . Here is modification

POST _search
{
   "query": {
      "filtered": {
         "query": {
            "match": {
               "body": "bitcoin"
            }
         },
         "filter": {
            "not": {
               "term": {
                  "subreddit": "bitcoin"
               }
            }
         }
      }
   }
}

希望这有帮助!!

这篇关于elasticsearch 排除具有值的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 02:28