# Searching multiple fields and defining relevance of each field individually from a single search box

**URL:** <https://discuss.elastic.co/t/searching-multiple-fields-and-defining-relevance-of-each-field-individually-from-a-single-search-box/14346>\
**Category:** Elasticsearch\
**Created:** [November 11, 2013, 9:26am UTC](https://discuss.elastic.co/t/searching-multiple-fields-and-defining-relevance-of-each-field-individually-from-a-single-search-box/14346 "2013-11-11T09:26:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastian\_paetzold](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastian_paetzold/32/1986_2.png) [@sebastian\_paetzold](https://discuss.elastic.co/u/sebastian_paetzold)\
**Post date:** [November 11, 2013, 9:26am UTC](https://discuss.elastic.co/t/searching-multiple-fields-and-defining-relevance-of-each-field-individually-from-a-single-search-box/14346/1 "2013-11-11T09:26:43Z")

</div>

Hi there,

I'm currently trying to find a solution to the following problem which I  
failed to solve via Google etc.

Imagine a index containing persons with the fields first name and last name  
(in reality there are even more to be searched fields like address).  
I would like to search these fields by providing the user a single line  
search box. So for example the user enters "chr pohl" in the search box, a  
query like "_chr_ AND _pohl_" should be constructed from it. In the past I  
used a combined field which just concats the first name and last name  
before indexing in ES and searched on this field. That worked pretty well.

However now I would like to do rank documents with a hit in the last name  
field higher than in the first name field. How could I do that? I tried a  
multi match query like

{  
"query": {  
"multi\_match": {  
"query": "Christian AND Dorn",  
"fields": ["firstName", "lastName"]  
}  
},  
"fields": ["firstName", "lastName"]  
}

Of course this works not quite as expected as the terms are rewritten as a  
should clause. So instead of narrowing my search results by being more  
precise (enter more letters basically) more and more search results are  
returned. Furthermore I'm pretty sure that multi match does not parse the  
query string as specified above (so the AND above is yet another search  
term and leads for example to found Andrea's). However I need something  
like a multi match to rank certain fields higher.

End of story: Documents are returned which do not feature ALL of the search  
terms. More terms in the search box leads to more documents returned, not  
less.

"firstName": "Andrea"  
"lastName": "Christian"

"firstName": "Ilse"  
"lastName": "Christian"

"firstName": "Maren"  
"lastName": "Christian"

So how could I do this properly? How can I rank certain fields higher and  
still be searching across fields as outlined above?

Thanks for your help.

-Sebastian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 14, 2013, 11:04am UTC](https://discuss.elastic.co/t/searching-multiple-fields-and-defining-relevance-of-each-field-individually-from-a-single-search-box/14346/2 "2013-11-14T11:04:19Z")

</div>

Hey there Sebastian,

having a quick peek at your query and reading the multi\_match/match query  
docs, it seems you are actually executing an or connected query. In order  
to change this, you would need to set the 'operator' option inside of the  
multi\_match query to 'and'. What happens here (with the standard analyzer)  
is that "christian and dorn" will remove stopwords and become 'christian  
dorn', which then becomes an or query.

You can do field boosting by using the ^ notation in the fields field...  
see

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Hope this helps, or otherwise I got your requirement wrong 🙂

--Alex

On Mon, Nov 11, 2013 at 10:26 AM, [sebastian.paetzold@ysura.com](mailto:sebastian.paetzold@ysura.com) wrote:

> Hi there,
> 
> I'm currently trying to find a solution to the following problem which I  
> failed to solve via Google etc.
> 
> Imagine a index containing persons with the fields first name and last  
> name (in reality there are even more to be searched fields like address).  
> I would like to search these fields by providing the user a single line  
> search box. So for example the user enters "chr pohl" in the search box, a  
> query like "_chr_ AND _pohl_" should be constructed from it. In the past I  
> used a combined field which just concats the first name and last name  
> before indexing in ES and searched on this field. That worked pretty well.
> 
> However now I would like to do rank documents with a hit in the last name  
> field higher than in the first name field. How could I do that? I tried a  
> multi match query like
> 
> {  
> "query": {  
> "multi\_match": {  
> "query": "Christian AND Dorn",  
> "fields": ["firstName", "lastName"]  
> }  
> },  
> "fields": ["firstName", "lastName"]  
> }
> 
> Of course this works not quite as expected as the terms are rewritten as a  
> should clause. So instead of narrowing my search results by being more  
> precise (enter more letters basically) more and more search results are  
> returned. Furthermore I'm pretty sure that multi match does not parse the  
> query string as specified above (so the AND above is yet another search  
> term and leads for example to found Andrea's). However I need something  
> like a multi match to rank certain fields higher.
> 
> End of story: Documents are returned which do not feature ALL of the  
> search terms. More terms in the search box leads to more documents  
> returned, not less.
> 
> "firstName": "Andrea"  
> "lastName": "Christian"
> 
> "firstName": "Ilse"  
> "lastName": "Christian"
> 
> "firstName": "Maren"  
> "lastName": "Christian"
> 
> So how could I do this properly? How can I rank certain fields higher and  
> still be searching across fields as outlined above?
> 
> Thanks for your help.
> 
> -Sebastian
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:07am UTC](https://discuss.elastic.co/t/searching-multiple-fields-and-defining-relevance-of-each-field-individually-from-a-single-search-box/14346/3 "2017-07-06T02:07:04Z")

</div>


