# Prefix searching across several string fields with different boosts?

**URL:** <https://discuss.elastic.co/t/prefix-searching-across-several-string-fields-with-different-boosts/7994>\
**Category:** Elasticsearch\
**Created:** [June 6, 2012, 10:53am UTC](https://discuss.elastic.co/t/prefix-searching-across-several-string-fields-with-different-boosts/7994 "2012-06-06T10:53:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Sviridov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_sviridov/32/31375_2.png) [@Alexander\_Sviridov](https://discuss.elastic.co/u/Alexander_Sviridov)\
**Post date:** [June 6, 2012, 10:53am UTC](https://discuss.elastic.co/t/prefix-searching-across-several-string-fields-with-different-boosts/7994/1 "2012-06-06T10:53:04Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 10, 2012, 9:22pm UTC](https://discuss.elastic.co/t/prefix-searching-across-several-string-fields-with-different-boosts/7994/2 "2012-06-10T21:22:59Z")

</div>

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](mailto: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!

---

<div class="post-metadata">

**Author:** ![Alexander\_Sviridov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_sviridov/32/31375_2.png) [@Alexander\_Sviridov](https://discuss.elastic.co/u/Alexander_Sviridov)\
**Post date:** [June 14, 2012, 11:53am UTC](https://discuss.elastic.co/t/prefix-searching-across-several-string-fields-with-different-boosts/7994/3 "2012-06-14T11:53:15Z")

</div>

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](mailto: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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:24am UTC](https://discuss.elastic.co/t/prefix-searching-across-several-string-fields-with-different-boosts/7994/4 "2017-07-06T03:24:14Z")

</div>


