# How to write java code for Custom Filters Score Query

**URL:** <https://discuss.elastic.co/t/how-to-write-java-code-for-custom-filters-score-query/9800>\
**Category:** Elasticsearch\
**Created:** [November 23, 2012, 6:05am UTC](https://discuss.elastic.co/t/how-to-write-java-code-for-custom-filters-score-query/9800 "2012-11-23T06:05:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiruba\_2](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kiruba\_2](https://discuss.elastic.co/u/kiruba_2)\
**Post date:** [November 23, 2012, 6:05am UTC](https://discuss.elastic.co/t/how-to-write-java-code-for-custom-filters-score-query/9800/1 "2012-11-23T06:05:30Z")

</div>

Hi all,

how to write java code for the following json.

_{_

- "custom\_filters\_score" : {\*
- 

```
   "query" : {*

```

- 

```
       "match_all" : {}*

```

- 

```
   },*

```

- 

```
   "filters" : [*

```

- 

```
       {*

```

- 

```
           "filter" : { "range" : { "age" : {"from" : 0, "to" : 10} } 

```

},\*

- 

```
           "boost" : "3"*

```

- 

```
       },*

```

- 

```
       {*

```

- 

```
           "filter" : { "range" : { "age" : {"from" : 10, "to" : 20} 

```

} },\*

- 

```
           "boost" : "2"*

```

- 

```
       }*

```

- 

```
   ],*

```

- 

```
   "score_mode" : "first"*

```

- }\*  
_}_
- 
- 

thanks,

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 24, 2012, 12:47am UTC](https://discuss.elastic.co/t/how-to-write-java-code-for-custom-filters-score-query/9800/2 "2012-11-24T00:47:46Z")

</div>

Take a look at CustomScoreSearchTests.testCustomFiltersScore()[https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java#L263](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java#L263)test. The example there is using termFilter(), which you will need to  
replace with rangeFilter(). You can find an example of how to build  
rangeFilter() in the  
SimpleIndexQueryParserTests.testRangeFilteredQueryBuilder()[https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java#L709](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java#L709)  
test.

On Friday, November 23, 2012 1:05:30 AM UTC-5, karan.r wrote:

> Hi all,
> 
> how to write java code for the following json.
> 
> _{_
> 
> - "custom\_filters\_score" : {\*
> - 
> 
> ```
> "query" : {*
> 
> ```
> 
> - 
> 
> ```
> "match_all" : {}*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "filters" : [*
> 
> ```
> 
> - 
> 
> ```
> {*
> 
> ```
> 
> - 
> 
> ```
> "filter" : { "range" : { "age" : {"from" : 0, "to" : 10} 
> 
> ```
> 
> } },\*
> 
> - 
> 
> ```
> "boost" : "3"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> {*
> 
> ```
> 
> - 
> 
> ```
> "filter" : { "range" : { "age" : {"from" : 10, "to" : 
> 
> ```
> 
> 20} } },\*
> 
> - 
> 
> ```
> "boost" : "2"*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> ],*
> 
> ```
> 
> - 
> 
> ```
> "score_mode" : "first"*
> 
> ```
> 
> - }\*  
> _}_
> - 
> - 
> 
> thanks,

--

---

<div class="post-metadata">

**Author:** ![kiruba\_2](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kiruba\_2](https://discuss.elastic.co/u/kiruba_2)\
**Post date:** [November 26, 2012, 5:53am UTC](https://discuss.elastic.co/t/how-to-write-java-code-for-custom-filters-score-query/9800/3 "2012-11-26T05:53:14Z")

</div>

thanks motov.

On Saturday, November 24, 2012 6:17:46 AM UTC+5:30, Igor Motov wrote:

> Take a look at CustomScoreSearchTests.testCustomFiltersScore()[https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java#L263](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java#L263)test. The example there is using termFilter(), which you will need to  
> replace with rangeFilter(). You can find an example of how to build  
> rangeFilter() in the  
> SimpleIndexQueryParserTests.testRangeFilteredQueryBuilder()[https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java#L709](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java#L709)  
> test.
> 
> On Friday, November 23, 2012 1:05:30 AM UTC-5, karan.r wrote:
> 
> > Hi all,
> > 
> > how to write java code for the following json.
> > 
> > _{_
> > 
> > - "custom\_filters\_score" : {\*
> > - 
> > 
> > ```
> > "query" : {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "match_all" : {}*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "filters" : [*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "filter" : { "range" : { "age" : {"from" : 0, "to" : 
> > 
> > ```
> > 
> > 10} } },\*
> > 
> > - 
> > 
> > ```
> > "boost" : "3"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "filter" : { "range" : { "age" : {"from" : 10, "to" : 
> > 
> > ```
> > 
> > 20} } },\*
> > 
> > - 
> > 
> > ```
> > "boost" : "2"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > ],*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "score_mode" : "first"*
> > 
> > ```
> > 
> > - }\*  
> > _}_
> > - 
> > - 
> > 
> > thanks,

--

---

<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:02am UTC](https://discuss.elastic.co/t/how-to-write-java-code-for-custom-filters-score-query/9800/4 "2017-07-06T03:02:59Z")

</div>


