2016-06-18 3 views
0

私は、複数のフィールドを持つ単純なクエリを実行していて、与えられたドキュメントの古い日数に基づいて減衰関数を適用しようとしています。次のクエリは私の試みです:次のマッピングでElasticsearch date decay function、Rails

{ 
     query: { 
      function_score:{ 
       query: { 
        multi_match: { 
         query: query, 
         fields: ['name', 'location'] 
        }, 
        functions: [{ 
         gauss: { 
          created_at: { 
           origin: 'now', 
           scale: '1d', 
           offset: '2d', 
           decay: 0.5 
          } 
         } 
        }] 
       } 
      } 
     } 
    } 

mappings dynamic: 'false' do 
    indexes :name, analyzer: 'english' 
    indexes :location, analyzer: 'english' 
    indexes :created_at, type: 'date' 
end 

`` `

は、次のエラーを与える: [400] {"error":{"root_cause":[{"type":"query_parsing_exception","reason":"No query registered for [gauss]","index":"people","line":1,"col":143}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query_fetch","grouped":true,"failed_shards":[{"shard":0,"index":"jobs","node":"abcdefgZq1PMsd882foA","reason":{"type":"query_parsing_exception","reason":"No query registered for [gauss]","index":"people","line":1,"col":143}}]},"status":400}

答えて

0

functionsは1を移動する必要がありますレベルが高く、function_scoreの内部で、queryの内部にはありません。

{ 
    query: { 
     function_score:{ 
      functions: [{ 
       gauss: { 
        created_at: { 
         origin: 'now', 
         scale: '1d', 
         offset: '2d', 
         decay: 0.5 
        } 
       } 
      }], 
      query: { 
       multi_match: { 
        query: query, 
        fields: ['name', 'location'] 
       } 
      } 
     } 
    } 
} 
関連する問題