# Help with query

**URL:** https://discuss.elastic.co/t/help-with-query/5050
**Category:** Elasticsearch
**Created:** [August 3, 2011, 10:23pm UTC](https://discuss.elastic.co/t/help-with-query/5050 "2011-08-03T22:23:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Adrian1](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@Adrian1](https://discuss.elastic.co/u/Adrian1)
#### Post date: [August 3, 2011, 10:23pm UTC](https://discuss.elastic.co/t/help-with-query/5050/1 "2011-08-03T22:23:41Z")

</div>

Hi, trying to do a query against 3 fields, and then boost by more  
recent date. The query executes ok, but it seems like none of the  
boosting is really working. Any help appreciated. Here's my code:  
(groovy code)

DateTimeFormatter fmt = ISODateTimeFormat.dateTime();  
DateTime dt = new DateTime(new Date());  
dt = dt.minusDays(30)  
String jodaThen = fmt.print(dt)

```
    def bodyContent = [query: [

            bool: [
                    must: [
                            dis_max: [
                                    tie_breaker: 0.7,
                                    boost: 1.2,
                                    queries: [
                                            [
                                                    text: [
                                                            title:

```

[

query: query.toLowerCase(),

boost: 4  
]  
]  
],  
[  
text: [

keywords: [

query: query.toLowerCase(),

boost: 3  
]  
]

```
                                            ],
                                            [
                                                    text: [

```

description: [

query: query.toLowerCase(),

boost: 2  
]  
]

```
                                            ]

                                    ]
                            ]
                    ],
                    should: [

                            range: [
                                    dateCreated: [
                                            boost: 5,
                                            gte: jodaThen
                                    ]
                            ],

                            range: [
                                    dateCreated: [
                                            lt: jodaThen,
                                            boost: 1
                                    ]
                            ]

                    ]
            ]
    ]]

```

--Adrian

---

<div class="post-metadata">

### Author: ![Tania](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tania/32/3123_2.png) [@Tania](https://discuss.elastic.co/u/Tania)
#### Post date: [August 4, 2011, 11:13am UTC](https://discuss.elastic.co/t/help-with-query/5050/2 "2011-08-04T11:13:50Z")

</div>

Hi Adrian,  
I am also interested in boosting my results by more recent date, this  
is, modifying they score so as to _newer documents have a slightly  
bigger score than older ones_ (notice that I _don't mean sorting by  
date_). But I am using the API (curl ...). I was thinking abut opening  
a new issue but just seen yours.  
I dont know even which tool should I use to achieve it. I have made  
some testing with custom score but the performance is very poor. I see  
that you are using dis\_max and tie\_breaker. Could you explain it a  
little?

Thanks in advance!

Tania

On 4 ago, 00:23, Adrian [adrian.ros...@gmail.com](mailto:adrian.ros...@gmail.com) wrote:

> Hi, trying to do a query against 3 fields, and then boost by more  
> recent date. The query executes ok, but it seems like none of the  
> boosting is really working. Any help appreciated. Here's my code:  
> (groovy code)
> 
> DateTimeFormatter fmt = ISODateTimeFormat.dateTime();  
> DateTime dt = new DateTime(new Date());  
> dt = dt.minusDays(30)  
> String jodaThen = fmt.print(dt)
> 
> ```
> def bodyContent = [query: [
> 
> bool: [
> must: [
> dis_max: [
> tie_breaker: 0.7,
> boost: 1.2,
> queries: [
> [
> text: [
> title:
> 
> ```
> 
> [
> 
> query: query.toLowerCase(),
> 
> boost: 4  
> ]  
> ]  
> ],  
> [  
> text: [
> 
> keywords: [
> 
> query: query.toLowerCase(),
> 
> boost: 3  
> ]  
> ]
> 
> ```
> ],
> [
> text: [
> 
> ```
> 
> description: [
> 
> query: query.toLowerCase(),
> 
> boost: 2  
> ]  
> ]
> 
> ```
> ]
> 
> ]
> ]
> ],
> should: [
> 
> range: [
> dateCreated: [
> boost: 5,
> gte: jodaThen
> ]
> ],
> 
> range: [
> dateCreated: [
> lt: jodaThen,
> boost: 1
> ]
> ]
> 
> ]
> ]
> ]]
> 
> ```
> 
> --Adrian

---

<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: [August 4, 2011, 7:51pm UTC](https://discuss.elastic.co/t/help-with-query/5050/3 "2011-08-04T19:51:10Z")

</div>

Hard to tell from the code in the mail, but can you use explain on the  
search request which should provide more information on how the scoring of  
each doc was computed.

On Thu, Aug 4, 2011 at 1:23 AM, Adrian [adrian.roston@gmail.com](mailto:adrian.roston@gmail.com) wrote:

> Hi, trying to do a query against 3 fields, and then boost by more  
> recent date. The query executes ok, but it seems like none of the  
> boosting is really working. Any help appreciated. Here's my code:  
> (groovy code)
> 
> DateTimeFormatter fmt = ISODateTimeFormat.dateTime();  
> DateTime dt = new DateTime(new Date());  
> dt = dt.minusDays(30)  
> String jodaThen = fmt.print(dt)
> 
> ```
> def bodyContent = [query: [
> 
> bool: [
> must: [
> dis_max: [
> tie_breaker: 0.7,
> boost: 1.2,
> queries: [
> [
> text: [
> title:
> 
> ```
> 
> [
> 
> query: query.toLowerCase(),
> 
> boost: 4  
> ]  
> ]  
> ],  
> [  
> text: [
> 
> keywords: [
> 
> query: query.toLowerCase(),
> 
> boost: 3  
> ]  
> ]
> 
> ```
> ],
> [
> text: [
> 
> ```
> 
> description: [
> 
> query: query.toLowerCase(),
> 
> boost: 2  
> ]  
> ]
> 
> ```
> ]
> 
> ]
> ]
> ],
> should: [
> 
> range: [
> dateCreated: [
> boost: 5,
> gte: jodaThen
> ]
> ],
> 
> range: [
> dateCreated: [
> lt: jodaThen,
> boost: 1
> ]
> ]
> 
> ]
> ]
> ]]
> 
> ```
> 
> --Adrian

---

<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:58am UTC](https://discuss.elastic.co/t/help-with-query/5050/4 "2017-07-06T03:58:13Z")

</div>


