【问题标题】:How to query nested indexes using Retire如何使用 Retire 查询嵌套索引
【发布时间】:2015-01-09 02:30:04
【问题描述】:

我有一个Article 模型:

class Article < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks

  settings default_options do
    mapping do
      indexes :id, index: :not_analyzed
      indexes :roles do
        indexes :machine_name, analyzer: 'keyword'
      end
      indexes :published_at, type: 'date', include_in_all: false
    end
  end
end

default_options 在哪里:

index: { store: { type: Rails.env.test? ? :memory : :niofs },
         analysis: {
           analyzer: {
             default: {
               tokenizer: "standard",
               filter: ["asciifolding", "lowercase", "snowball"],
               char_filter: ["html_strip"]
             }
           }
        }

我只是想在过滤角色的同时搜索文章,但我不知道该怎么做。我一直在尝试这样的事情但没有成功:

Tire.search("article") do
  query { string 'foo bar baz' }
  filter :nested, { path:'roles',
                    query: {
                      filtered: {
                        query: {
                          match_all: {}
                        },
                        filter: {
                          term:{'roles.machine_name' => ['da']}
                        }
                      }
                    }
                  }
end

这给了我这个错误:

QueryParsingException[[development-oaciq::application-article] [nested] nested object under path [roles] is not of nested type];

【问题讨论】:

    标签: ruby-on-rails elasticsearch tire


    【解决方案1】:

    找到这个question 后,似乎不需要nested 过滤器,可以这样做:

    Tire.search("article") do
      query do
        string 'foo bar baz'
        term 'roles.machine_name', 'test'
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      相关资源
      最近更新 更多