2013-11-27 57 views
1

輪胎多搜索我想就Elasticsearch多查詢通過輪胎但生JSON 我可以一個請求這樣與原始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 

你現在我所能做的是如何使它工作? 謝謝

回答

1

我找到了解決方案。 其實,在我的案例中搜索方法是要求:有效載荷密鑰中的選項參數

@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