如何将弹性搜索JSON转换为与Tire兼容的查询

时间:2012-09-28 06:47:32

标签: elasticsearch tire

我无法将以下有效的JSON查询转换为弹性搜索到ruby gem“轮胎”等效内容。任何帮助都非常适合......


{ 
    "query" : {
        "term" : { "_all" : "coffee" }
    },
    "filter" : {
        "or" : [
            {
                "term" : { "email_store" : true }
            },
            {
                "term" : { "phone_store" : false }
            }
        ]
    }
}

1 个答案:

答案 0 :(得分:1)

这将是Tire DSL中的等效符号:

require 'tire'

s = Tire.search('articles') do
  query do
    term :_all, 'coffee'
  end

  filter :or, { term: { email_store: true  } },
              { term: { phone_store: false } }
end

puts s.to_json

查看https://github.com/karmi/tire/blob/master/test/integration/filters_test.rb#L25-29