如何在elasticsearch中的索引字段中使用不查询

时间:2016-10-25 06:52:17

标签: elasticsearch

这是映射。

curl -XPUT 'localhost:9200/products/' -d '{
    "settings" : {
        "index" : {
            "number_of_shards" : 6, 
            "number_of_replicas" : 1 
        }
    },
    "mappings" : {
        "product" : {
          "_all":{ "enabled": true  },
          "properties":{
            "id" : { "type" : "string", "index" : "not_analyzed", "include_in_all": true },
            "description" : { "type" : "string" },
            "title" : { "type" : "string", "boost" : 2 },
      }
        }
    }
}'

我不想收到没有说明的广告。但正如你在映射中所看到的“描述”有一个索引。 那么如何在描述中使用不查询? 请帮帮我。

我看过弹性搜索的文档,我使用了这个查询。

**query => {
    filtered => {
        filter => {
            not => {
                filter => {
                    term  => {description  => ''}
                }
            }
        },
        query => {
            match => { _all => $q }
        }
    }
}**

但它不起作用,我认为因为描述的索引是对的吗?

1 个答案:

答案 0 :(得分:2)

对于2.4,这将是正确的语法和查询方法:

{
  "query": {
    "bool": {
      "must": [
        {"match_all": {}}
      ],
      "filter": {
        "bool": {
          "must": [
            {
              "exists": {
                "field": "description"
              }
            },
            {
              "wildcard": {
                "description": "*"
              }
            }
          ]
        }
      }
    }
  }
}

而不是filtered您有bool must作为查询而filter as filter. What's inside of必须is what you have as query and what's inside of过滤is what you have as filter. The approach you used with过滤`在ES中已弃用2.X。

相关问题