弹性搜索排除结果与价值 [英] elasticsearch exclude results with value

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

问题描述

我如何执行搜索,不包括字段具有特定值的结果?

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

我有一个Reddit评论数据库,我想要找比特币提及,但是排除bitcoin 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

推荐答案

这是愚蠢的错误,

你必须在查询中包括过滤的查询。这是修改

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

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

希望这有帮助!!

这篇关于弹性搜索排除结果与价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆