Prefix searching across several string fields with different boosts?


(Alexander Sviridov) #1

Hello!
I have an index for postal addresses. It includes street name, city,
house number etc.

What I'm trying to do is fuzzy search across all this fields with
different boost, i.e. query like "Washing" should return all entries
with street: "Washington street" and "10 Washington" should place
entry with street: "Washington street" and house_number: "10" above
all other entries with same street or house number. Also, city name
should work more like filter — if user will start query with "New-
York", I want to restrict search results to New-York, not show him all
NY results.

I've tried manually pack all properties in one string and index it,
but it doesn't allow set different boosting on different fields...

What is best way to run such a query?

Thank you!


(Shay Banon) #2

If you have different fields for street name, and city, you can create a
bool query with should clauses with a query on each field, and associate a
boost level with each one corresponding to the boosting you are after.

On Wed, Jun 6, 2012 at 12:53 PM, Alexander Sviridov <
alexander.sviridov@gmail.com> wrote:

Hello!
I have an index for postal addresses. It includes street name, city,
house number etc.

What I'm trying to do is fuzzy search across all this fields with
different boost, i.e. query like "Washing" should return all entries
with street: "Washington street" and "10 Washington" should place
entry with street: "Washington street" and house_number: "10" above
all other entries with same street or house number. Also, city name
should work more like filter — if user will start query with "New-
York", I want to restrict search results to New-York, not show him all
NY results.

I've tried manually pack all properties in one string and index it,
but it doesn't allow set different boosting on different fields...

What is best way to run such a query?

Thank you!


(Alexander Sviridov) #3

Thank you for answering!
I'd use this approach if I had separate query parts for the street name,
house number etc.

Unfortunately this query is a freeform string entered by the user, so I'll
have to split it in order
to use a separate boolean clauses, and this is exactly what I want to avoid.

Is there a way to tell elasticsearch that I want documents with exact match
to have highest score?

Like if the query is "1 Baker Street, London" and I have document where
city_name=London, street_name=Baker Street, and house_number=1.

On Monday, June 11, 2012 1:22:59 AM UTC+4, kimchy wrote:

If you have different fields for street name, and city, you can create a
bool query with should clauses with a query on each field, and associate a
boost level with each one corresponding to the boosting you are after.

On Wed, Jun 6, 2012 at 12:53 PM, Alexander Sviridov <
alexander.sviridov@gmail.com> wrote:

Hello!
I have an index for postal addresses. It includes street name, city,
house number etc.

What I'm trying to do is fuzzy search across all this fields with
different boost, i.e. query like "Washing" should return all entries
with street: "Washington street" and "10 Washington" should place
entry with street: "Washington street" and house_number: "10" above
all other entries with same street or house number. Also, city name
should work more like filter — if user will start query with "New-
York", I want to restrict search results to New-York, not show him all
NY results.

I've tried manually pack all properties in one string and index it,
but it doesn't allow set different boosting on different fields...

What is best way to run such a query?

Thank you!


(system) #4