空或零字段过滤器不适用于弹性搜索

时间:2014-12-05 17:00:30

标签: ruby-on-rails elasticsearch

我正在尝试创建一个ES查询,其中3个必须为真:布尔字段必须为true,搜索项必须与字段匹配,第三个字段必须为null。这是我在YML中的查询(我使用的是mongoid-elasticsearch)

:query:
  :filtered:
    :filter:
      :bool:
        :must:
        - :term:
            :qualified: true
        - :term:
            :name: mukluk
        - :missing:
            :field: :location_ids
            :existence: true
            :null_value: true

在此查询" name"是一个字段的名称。

这导致零命中。

如果我删除最后一个键(缺少),查询工作正常。这里是JSON中的实际记录(这是删除丢失的过滤器时返回的实际弹性搜索JSON,因此您可以看到location_ids实际上是零):

{
  "took"=> 1,
  "timed_out"=> false,
  "_shards"=> {
    "total"=> 5,
    "successful"=> 5,
    "failed"=> 0
  },
  "hits"=> {
    "total"=> 1,
    "max_score"=> 1.0,
    "hits"=> [
      {
        "_index"=> "items",
        "_type"=> "item",
        "_id"=> "5480b53c73d5495ce600062b",
        "_score"=> 1.0,
        "_source"=> {
          "name"=> "FitFlop mukluk (black)",
          "description"=> "FitFlop mukluk (black)",
          "qualified"=> true,
          "retailer_id"=> "5470a7f273d549817c1882de",
          "location_ids"=> nil
        }
      }
    ]
  }
}

了解location_ids如何为零?如何让它成为查询的一部分?

btw,这里是提交的实际查询的正文json:

{
  \"query\": {
    \"filtered\": {
      \"filter\": {
        \"bool\": {
          \"must\": [
            {
              \"term\": {
                \"qualified\": true
              }
            },
            {
              \"term\": {
                \"name\": \"mukluk\"
              }
            }
          ]
        }
      }
    }
  },
  \"size\": 200,
  \"from\": 0
}

更新:

这是失败查询的输出:

{
  "took"=> 1,
  "timed_out"=> false,
  "_shards"=> {
    "total"=> 5,
    "successful"=> 5,
    "failed"=> 0
  },
  "hits"=> {
    "total"=> 0,
    "max_score"=> nil,
    "hits"=> []
  }
}

以下是映射:

index_mappings: {
  name: {
    type: 'multi_field',
    fields: {
      name: {
        type: 'string',
        analyzer: 'snowball'
      },
      description: {
        type: 'string', 
        analyzer: 'snowball'
      },
      qualfied: {
        type: 'boolean', 
        index: :not_analyzed
      },
      location_ids: {
        type: 'string', 
        index: :not_analyzed
      }
    }
  },
  tags: {
    type: 'string', 
    include_in_all: false
  },
  wrapper: :load
}

0 个答案:

没有答案