我想通过Tire在Elasticsearch上进行多重查询,但要使用原始JSON
我可以像这样单个请求

@search = Tire.search('questions', query: {
    function_score: {
      query: {
        bool: {
            must: [
                {
                    terms: {
                        interests: [2943,5106,3540,1443,3639]
                    }
                }
            ]
        }
      },
      random_score: {}
    }
  })

但是我不能多重。
我想要这样的东西,但目前还不正确...
@search = Tire.multi_search 'questions' do


    search :level2 do
        query: {
            function_score: {
              query: {
                bool: {
                    must: [{
                        terms: {
                        interests: [5090,2938,3062]
                        }}]
                }
              },
              random_score: {}
            }
        }
    end

end

您现在如何才能使它正常工作?
谢谢

最佳答案

我找到了解决方案。
实际上,就我而言,搜索方法要求在options参数中使用:payload键

@search = Tire.multi_search 'questions' do

            search( :level1, :payload => {
                                query: {
                                function_score: {
                                  query: {
                                    bool: {
                                        must: [
                                            {
                                                terms: {
                                                    interests: [2943,5106,3540,1443,3639]
                                                }
                                            },{
                                                term: {
                                                    difficulty: 1
                                                }
                                            }
                                        ]
                                    }
                                  },
                                  random_score: {}
                                }
                             }})

            search( :level2, :payload => {
                                query: {
                                function_score: {
                                  query: {
                                    bool: {
                                        must: [
                                            {
                                                terms: {
                                                    interests: [5160,2938,3062]
                                                }
                                            },{
                                                term: {
                                                    difficulty: 2
                                                }
                                            }
                                        ]
                                    }
                                  },
                                  random_score: {}
                                }
                             }})

        end

关于ruby-on-rails - 使用RAW Json进行轮胎多重搜索,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20251041/

10-11 15:39