简体   繁体   中英

Elasticsearch field value factor with multi matching?

I'm using this to search my outfits:

def self.search(query, purchasedlow, purchasedhigh)
__elasticsearch__.search(
{
  query: {
    function_score: {
      query: {
        bool: {
          filter: [
            {
              multi_match: {
                query: query,
                fields: ['name','description','material']
              }
            },
            {
              range: {
                purchased: { lte: purchasedhigh.to_i, gte: purchasedlow.to_i},
              },          
            }
          ]
        }
      }
    }
  }
}
)
end

But I don't know how to add this code:

    field_value_factor: {
      field: "likes",
      factor: "100"
    }

I know that I'm supposed to put it after the function score, so that the calculated score is then multiplied by the amount of likes to make the final score, but when I put the code after the function_score, I get the following error:

[400] {"error":{"root_cause":[{"type":"parsing_exception","reason":"[function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":232}],"type":"parsing_exception","reason":"[function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":232},"status":400}

Where do I need to put the field value factor so that it works correctly?

I used field_value_factor in one of my queries like this:

@products = Product.search(
 query:{
   function_score:{
     query:{
       bool:{
         must:{
           multi_match:{
             fields: ['brand^5', '_all'],
             query: "#{query}",
             fuzziness: "AUTO"
           }
         },

           filter:{
             bool:{
               must:[
                 {term: {"brand":"NordicTrack"}},
                 {term: {"product_type":"Treadmill"}}
               ]
             }
           }

       }
     },
     field_value_factor:{
        field: "popularity",
        modifier: "log1p"
     }
   }
 })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM