【问题标题】:elasticsearch exclude results with value弹性搜索排除具有值的结果
【发布时间】:2014-10-10 18:59:44
【问题描述】:

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

我有一个 Reddit cmets 数据库,我想查找提到的比特币,但不包括比特币 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

【问题讨论】:

  • 查询有什么问题?你得到了什么?
  • @progrrammer 我添加了错误。
  • 不完整,复制所有错误。
  • @progrrammer 错误太长,这里是要点gist.github.com/kylelk/feca416156712eebad3e谢谢
  • 他可能收到了 400 Bad request

标签: elasticsearch


【解决方案1】:

这是一个愚蠢的错误,

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

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

希望这会有所帮助!

【讨论】:

猜你喜欢
  • 2018-03-08
  • 1970-01-01
  • 2014-07-21
  • 2012-01-24
  • 1970-01-01
  • 2012-08-23
  • 2015-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多