elasticsearch,Ruby On Rails,elasticsearch" /> elasticsearch,Ruby On Rails,elasticsearch" />

Ruby on rails 空或零字段筛选器不适用于弹性搜索

Ruby on rails 空或零字段筛选器不适用于弹性搜索,ruby-on-rails,elasticsearch,Ruby On Rails,elasticsearch,我正在尝试创建一个ES查询,其中有三件事必须为真:布尔字段必须为真,搜索项必须与字段匹配,第三个字段必须为空。这是我在YML中的查询,我正在使用mongoid elasticsearch :query: :filtered: :filter: :bool: :must: - :term: :qualified: true - :term: :name: mukluk

我正在尝试创建一个ES查询,其中有三件事必须为真:布尔字段必须为真,搜索项必须与字段匹配,第三个字段必须为空。这是我在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中的实际记录这是删除缺少的过滤器时返回的实际elasticsearch JSON,因此您可以看到位置_id实际上为nil:

{
  "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
        }
      }
    ]
  }
}
查看位置_id如何为零?如何将其作为查询的一部分

顺便说一句,下面是提交的实际查询的主体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
}

可以发布映射和实际的json响应吗?当然,下面是输出:[code]{take=>1,timed\u out=>false,{u shards=>{total=>5,successful=>5,failed=>0},hits=>{total=>0,max\u score=>nil,hits=>[]}[/code]@keety更新,提前谢谢,我怀疑你对映射有什么看法,b/c我现在看到它是一个字符串,即使数据是一个字符串数组。