简体   繁体   English

弹性搜索字符串查询

[英]Elastic search string query

I have database that looks like this:我有这样的数据库:

{ "test": true, "example": "string1" } {“测试”:真,“例子”:“string1”}

Im using elasticsearch string query to get data that contains specific strings, but I need to filter it to get results that has false in 'test' attribute.我使用 elasticsearch 字符串查询来获取包含特定字符串的数据,但我需要对其进行过滤以获取“test”属性中包含 false 的结果。 Is there any way to do this by string query?有没有办法通过字符串查询来做到这一点?

True and False values are not in quotes ! True 和 False 值不在引号中!

If you're using the query_string query, you can do it like this:如果您使用的是query_string查询,您可以这样做:

{
  "query": {
    "query_string": {
      "query": "test:false AND example:foobar"
    }
  }
}

You can also do it outside of the query_string query like this:您也可以像这样在query_string查询之外执行此操作:

{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "test": false
          }
        }
      ],
      "must": [
        {
          "query_string": {
            "query": "example:foobar"
          }
        }
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM