# How to Boost

**URL:** <https://discuss.elastic.co/t/how-to-boost/23451>\
**Category:** Elasticsearch\
**Created:** [April 28, 2015, 8:42pm UTC](https://discuss.elastic.co/t/how-to-boost/23451 "2015-04-28T20:42:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [April 28, 2015, 8:42pm UTC](https://discuss.elastic.co/t/how-to-boost/23451/1 "2015-04-28T20:42:56Z")

</div>

I am attempting to boost values for queries.

I'm searching across all fields and tables and returning 25 results for  
each type.

This is working fine however I need to Boost if the field name Name or the  
Field Name ID have the value in it.

I'm using ElasticSearchClient and sending this search.

search = new  
{

```
            query = new
            {
                query_string = new
                {
                    query = keyword,
                    default_field = "_all"
                }
            },
            from = 0,
            size = limitAllTypes,
            aggs = new
            {
                top_types = new
                {
                    terms = new
                    {
                        field = "_type"
                    },
                    aggs = new
                    {
                        top_type_hits = new
                        {
                            top_hits = new
                            {
                                size = limitPerType
                            }
                        }
                    }
                }
            }

```

ElasticsearchResponse searchResponse =  
client.Search("jdbc", search, null);

How do i tell this to boost the name and id fields over all other fields.

If I'm searching for "My Searched Company" and that is in the Name field I  
want it at the top of the list. vs in notes, addresses or whatever other  
columns etc.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ccffa252-30c4-444d-9bbb-cd28a1acec50%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ccffa252-30c4-444d-9bbb-cd28a1acec50%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpotisch](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@jpotisch](https://discuss.elastic.co/u/jpotisch)\
**Post date:** [April 29, 2015, 4:06pm UTC](https://discuss.elastic.co/t/how-to-boost/23451/2 "2015-04-29T16:06:46Z")

</div>

You could use a boosting query  
[http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html),  
or you could use a multi-match query  
[http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) and  
add a boost directly to the name and id fields. Something like:

{  
"multi\_match": {  
"fields": [  
"name^2",  
"id^2",  
"\_all"  
],  
"query": keyword,  
"type": "best\_fields"  
}  
}

That tells Elasticsearch to search all fields, but to additionally search  
name and id and double their score if they match (that's the "^2" part).  
the "best\_fields" type will use the best score from the name, id, and \_all  
searches. You might want most\_fields to rank records that contain your  
query terms in name _and_ id _and_ other fields even higher. Note that my  
snippet is using the Query DSL. The syntax for the client you're using will  
probably be slightly different but that's the general idea.

Also note that I've been using Elasticsearch less than a year though so  
there may be better approaches, but that's where I'd start.

-joel

On Tuesday, April 28, 2015 at 4:42:56 PM UTC-4, GWired wrote:

> I am attempting to boost values for queries.
> 
> I'm searching across all fields and tables and returning 25 results for  
> each type.
> 
> This is working fine however I need to Boost if the field name Name or the  
> Field Name ID have the value in it.
> 
> I'm using ElasticSearchClient and sending this search.
> 
> search = new  
> {
> 
> ```
> query = new
> {
> query_string = new
> {
> query = keyword,
> default_field = "_all"
> }
> },
> from = 0,
> size = limitAllTypes,
> aggs = new
> {
> top_types = new
> {
> terms = new
> {
> field = "_type"
> },
> aggs = new
> {
> top_type_hits = new
> {
> top_hits = new
> {
> size = limitPerType
> }
> }
> }
> }
> }
> 
> ```
> 
> ElasticsearchResponse searchResponse =  
> client.Search("jdbc", search, null);
> 
> How do i tell this to boost the name and id fields over all other fields.
> 
> If I'm searching for "My Searched Company" and that is in the Name field I  
> want it at the top of the list. vs in notes, addresses or whatever other  
> columns etc.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ff22e57d-cc39-43d9-b403-025e0f345cd1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ff22e57d-cc39-43d9-b403-025e0f345cd1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [May 1, 2015, 1:01am UTC](https://discuss.elastic.co/t/how-to-boost/23451/3 "2015-05-01T01:01:27Z")

</div>

I was able to get this to work in ES using head and got back what i needed.

However translating to [ElasticSearch.net](http://ElasticSearch.net) has been an issue.

I have an anonymous type doing a match all query and this works fine and  
dandy.

I am trying to do the multi\_match as above but it isn't returning any  
results. I'm not sure

var myfields = "["Name^20","Id^20","\_all"]"; \<- this gets no  
results  
var myfields = "["Name^20","Id^20","\_all"]"; \<- this crashes with  
all kinds of errors

How do you do these bracketed values?

```
        var search = new
        {

            query = new
            {
                multi_match = new
                {
                    fields = myfields,
                    query = keyword,
                    type = "best_fields",
                    use_dis_max= "true"
                }
            },
            from = 0,
            size = limitAllTypes,
            aggs = new
            {
                top_types = new
                {
                    terms = new
                    {
                        field = "_type"
                    },
                    aggs = new
                    {
                        top_type_hits = new
                        {
                            top_hits = new
                            {
                                size = limitPerType
                            }
                        }
                    }
                }
            }
        };

```

On Wednesday, April 29, 2015 at 12:06:47 PM UTC-4, Joel Potischman wrote:

> You could use a boosting query  
> [http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html),  
> or you could use a multi-match query  
> [http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) and  
> add a boost directly to the name and id fields. Something like:
> 
> {  
> "multi\_match": {  
> "fields": [  
> "name^2",  
> "id^2",  
> "\_all"  
> ],  
> "query": keyword,  
> "type": "best\_fields"  
> }  
> }
> 
> That tells Elasticsearch to search all fields, but to additionally search  
> name and id and double their score if they match (that's the "^2" part).  
> the "best\_fields" type will use the best score from the name, id, and \_all  
> searches. You might want most\_fields to rank records that contain your  
> query terms in name _and_ id _and_ other fields even higher. Note that  
> my snippet is using the Query DSL. The syntax for the client you're using  
> will probably be slightly different but that's the general idea.
> 
> Also note that I've been using Elasticsearch less than a year though so  
> there may be better approaches, but that's where I'd start.
> 
> -joel
> 
> On Tuesday, April 28, 2015 at 4:42:56 PM UTC-4, GWired wrote:
> 
> > I am attempting to boost values for queries.
> > 
> > I'm searching across all fields and tables and returning 25 results for  
> > each type.
> > 
> > This is working fine however I need to Boost if the field name Name or  
> > the Field Name ID have the value in it.
> > 
> > I'm using ElasticSearchClient and sending this search.
> > 
> > search = new  
> > {
> > 
> > ```
> > query = new
> > {
> > query_string = new
> > {
> > query = keyword,
> > default_field = "_all"
> > }
> > },
> > from = 0,
> > size = limitAllTypes,
> > aggs = new
> > {
> > top_types = new
> > {
> > terms = new
> > {
> > field = "_type"
> > },
> > aggs = new
> > {
> > top_type_hits = new
> > {
> > top_hits = new
> > {
> > size = limitPerType
> > }
> > }
> > }
> > }
> > }
> > 
> > ```
> > 
> > ElasticsearchResponse searchResponse =  
> > client.Search("jdbc", search, null);
> > 
> > How do i tell this to boost the name and id fields over all other fields.
> > 
> > If I'm searching for "My Searched Company" and that is in the Name field  
> > I want it at the top of the list. vs in notes, addresses or whatever other  
> > columns etc.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c331b066-75e8-491e-8ffc-e4f8539f100e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c331b066-75e8-491e-8ffc-e4f8539f100e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [May 1, 2015, 11:43am UTC](https://discuss.elastic.co/t/how-to-boost/23451/4 "2015-05-01T11:43:01Z")

</div>

I got it:

To add an array of var to an anonymous type add them like this.

```
        var field1 = new {field="Name^20"};
        var field2 = new {field = "_all"};
        var field3 = new {field = "Id^20"};
        var myfields = new [] {field1,field2};

```

This is slick now it puts the brackets in and there is no escaping 🙂

On Thursday, April 30, 2015 at 9:01:27 PM UTC-4, GWired wrote:

> I was able to get this to work in ES using head and got back what i needed.
> 
> However translating to [ElasticSearch.net](http://ElasticSearch.net) has been an issue.
> 
> I have an anonymous type doing a match all query and this works fine and  
> dandy.
> 
> I am trying to do the multi\_match as above but it isn't returning any  
> results. I'm not sure
> 
> var myfields = "["Name^20","Id^20","\_all"]"; \<- this gets  
> no results  
> var myfields = "["Name^20","Id^20","\_all"]"; \<- this crashes with  
> all kinds of errors
> 
> How do you do these bracketed values?
> 
> ```
> var search = new
> {
> 
> query = new
> {
> multi_match = new
> {
> fields = myfields,
> query = keyword,
> type = "best_fields",
> use_dis_max= "true"
> }
> },
> from = 0,
> size = limitAllTypes,
> aggs = new
> {
> top_types = new
> {
> terms = new
> {
> field = "_type"
> },
> aggs = new
> {
> top_type_hits = new
> {
> top_hits = new
> {
> size = limitPerType
> }
> }
> }
> }
> }
> };
> 
> ```
> 
> On Wednesday, April 29, 2015 at 12:06:47 PM UTC-4, Joel Potischman wrote:
> 
> > You could use a boosting query  
> > [http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html),  
> > or you could use a multi-match query  
> > [http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) and  
> > add a boost directly to the name and id fields. Something like:
> > 
> > {  
> > "multi\_match": {  
> > "fields": [  
> > "name^2",  
> > "id^2",  
> > "\_all"  
> > ],  
> > "query": keyword,  
> > "type": "best\_fields"  
> > }  
> > }
> > 
> > That tells Elasticsearch to search all fields, but to additionally search  
> > name and id and double their score if they match (that's the "^2" part).  
> > the "best\_fields" type will use the best score from the name, id, and \_all  
> > searches. You might want most\_fields to rank records that contain your  
> > query terms in name _and_ id _and_ other fields even higher. Note that  
> > my snippet is using the Query DSL. The syntax for the client you're using  
> > will probably be slightly different but that's the general idea.
> > 
> > Also note that I've been using Elasticsearch less than a year though so  
> > there may be better approaches, but that's where I'd start.
> > 
> > -joel
> > 
> > On Tuesday, April 28, 2015 at 4:42:56 PM UTC-4, GWired wrote:
> > 
> > > I am attempting to boost values for queries.
> > > 
> > > I'm searching across all fields and tables and returning 25 results for  
> > > each type.
> > > 
> > > This is working fine however I need to Boost if the field name Name or  
> > > the Field Name ID have the value in it.
> > > 
> > > I'm using ElasticSearchClient and sending this search.
> > > 
> > > search = new  
> > > {
> > > 
> > > ```
> > > query = new
> > > {
> > > query_string = new
> > > {
> > > query = keyword,
> > > default_field = "_all"
> > > }
> > > },
> > > from = 0,
> > > size = limitAllTypes,
> > > aggs = new
> > > {
> > > top_types = new
> > > {
> > > terms = new
> > > {
> > > field = "_type"
> > > },
> > > aggs = new
> > > {
> > > top_type_hits = new
> > > {
> > > top_hits = new
> > > {
> > > size = limitPerType
> > > }
> > > }
> > > }
> > > }
> > > }
> > > 
> > > ```
> > > 
> > > ElasticsearchResponse searchResponse =  
> > > client.Search("jdbc", search, null);
> > > 
> > > How do i tell this to boost the name and id fields over all other fields.
> > > 
> > > If I'm searching for "My Searched Company" and that is in the Name field  
> > > I want it at the top of the list. vs in notes, addresses or whatever other  
> > > columns etc.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8cd471ec-cbe9-485f-adc7-8ae23326f537%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8cd471ec-cbe9-485f-adc7-8ae23326f537%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:16am UTC](https://discuss.elastic.co/t/how-to-boost/23451/5 "2017-07-06T00:16:15Z")

</div>


