I am trying to create a search for a specific model called Location with indexes:
mapping do
indexes :_id, :as => "_id.to_s", :index => "not_analyzed"
indexes :name, analyzer: 'english'
indexes :address, analyzer: 'english', type: :string
indexes :country, type: :string
indexes :city, type: :string
indexes :province, type: :string
indexes :state, type: :string
indexes :postalcode, type: :string
indexes :latlng, type: :geo_point, lat_lon: true
end
The specific search must be like this:
http://localhost:3000/search?utf8=%E2%9C%93&q=Mezban+11&place=panchkula
where "Mezban 11" is the name of the Location and "panchkula" is the city of the Location.
The search must include NAME as a priority, CITY as second priority and ADDRESS, COUNTRY, PROVINCE, STATE, POSTALCODE as last priority.
This is the actual query i am testing:
search_name = Location.search({
query: {
bool: {
should: [
{
multi_match: {
query: "#{query}",
fields: ['name^5'],
type: 'best_fields'
}
},
{
multi_match: {
query: "#{place}",
fields: ['address', 'city'],
operator: 'and'
}
}
]
}
}
})
But this query brings me "Mezban 11 in Panchkula" as a 3er item in the query, and should be 1st because i am searching for a specific Location that live in my DataBase.
How should i create the query in elasticsearch to search in diferents fields but setting priority to the name of the Location?