# How to boosting a term using java API?

**URL:** <https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311>\
**Category:** Elasticsearch\
**Created:** [September 5, 2011, 6:54am UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311 "2011-09-05T06:54:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [September 5, 2011, 6:54am UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311/1 "2011-09-05T06:54:01Z")

</div>

Hi

I want to increase a significancy for some terms in the query.i am  
using following code for search:

SearchResponse searchResponse = client.prepareSearch(indexName)  
.setSearchType(SearchType.DEFAULT).setTypes(indexType)  
.setQuery(queryString(data).boost(20).field(indexColumn))  
.execute()  
.actionGet();

for example: my index contain the following data:

ABCD01EF  
ABCDEF02  
ABCDEFGH01  
ABCDEFGH02IJ

if i try to search ABCD01 i found zero hit count.  
please help me to how to boost search query then i found "ABCD01EF"  
when i search for "ABCD01".where i'm doing wrong? what need to be  
modified above code sample for search more relevance search using  
java?

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 5, 2011, 8:35am UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311/2 "2011-09-05T08:35:20Z")

</div>

I think that you should use a keyword analyzer for this field.

Boosting won't help you in that case.

HTH  
David 😉

Le 5 sept. 2011 à 08:54, sam [mishra.sameek@gmail.com](mailto:mishra.sameek@gmail.com) a écrit :

> Hi
> 
> I want to increase a significancy for some terms in the query.i am  
> using following code for search:
> 
> SearchResponse searchResponse = client.prepareSearch(indexName)  
> .setSearchType(SearchType.DEFAULT).setTypes(indexType)  
> .setQuery(queryString(data).boost(20).field(indexColumn))  
> .execute()  
> .actionGet();
> 
> for example: my index contain the following data:
> 
> ABCD01EF  
> ABCDEF02  
> ABCDEFGH01  
> ABCDEFGH02IJ
> 
> if i try to search ABCD01 i found zero hit count.  
> please help me to how to boost search query then i found "ABCD01EF"  
> when i search for "ABCD01".where i'm doing wrong? what need to be  
> modified above code sample for search more relevance search using  
> java?
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [September 5, 2011, 10:12am UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311/3 "2011-09-05T10:12:44Z")

</div>

Thanks for reply.can you please explain how keyword analyzer will help  
me.fot getting desire result.

On Sep 5, 1:35 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> I think that you should use a keyword analyzer for this field.
> 
> Boosting won't help you in that case.
> 
> HTH  
> David 😉
> 
> Le 5 sept. 2011 à 08:54, sam [mishra.sam...@gmail.com](mailto:mishra.sam...@gmail.com) a écrit :
> 
> > Hi
> 
> > I want to increase a significancy for some terms in the query.i am  
> > using following code for search:
> 
> > SearchResponse searchResponse = client.prepareSearch(indexName)  
> > .setSearchType(SearchType.DEFAULT).setTypes(indexType)  
> > .setQuery(queryString(data).boost(20).field(indexColumn))  
> > .execute()  
> > .actionGet();
> 
> > for example: my index contain the following data:
> 
> > ABCD01EF  
> > ABCDEF02  
> > ABCDEFGH01  
> > ABCDEFGH02IJ
> 
> > if i try to search ABCD01 i found zero hit count.  
> > please help me to how to boost search query then i found "ABCD01EF"  
> > when i search for "ABCD01".where i'm doing wrong? what need to be  
> > modified above code sample for search more relevance search using  
> > java?
> 
> > Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 5, 2011, 12:31pm UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311/4 "2011-09-05T12:31:36Z")

</div>

> Thanks for reply.can you please explain how keyword analyzer will help  
> me.fot getting desire result.  
> I think that your field does not contain human words (a sentence in fact) but  
> some keywords from your application.  
> That's why, for that same need, I use my self a keyword analyzer on that field.

So, Lucene does not try to make tokens from the field and let it as it is.  
BTW, if you want to search for abcd (and not ABCD), you will have probably to  
add a lowercase filter.

Something like :  
curl -X PUT [http://localhost:9200/myindex/](http://localhost:9200/myindex/) -d '  
{  
"settings":{  
"index":{  
"analysis":{  
"analyzer":{  
"key\_lowercase":{  
"tokenizer":"keyword",  
"filter":"lowercase"  
}  
}  
}  
}  
}  
}  
'

curl -X PUT [http://localhost:9200/myindex/mytype/\_mapping](http://localhost:9200/myindex/mytype/_mapping) -d '  
{  
"mytype":{  
"properties":{  
"myfield":{  
"analyzer":"key\_lowercase",  
"type":"string"  
}  
}  
}  
}  
'

After setting your mapping for that field, you will be able to perform a prefix  
search or a term search or a wildcard (cost more).

HTH

--  
David Pilato  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [September 5, 2011, 1:42pm UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311/5 "2011-09-05T13:42:00Z")

</div>

thanks for reply.perhaps my question is misunderstood.define example  
not contain any predefined keyword.my index can any human words or  
sentence.e.g

## index file:

Arosys Technologies  
IBM  
Infosys Technologies Ltd  
Arosys Technologies P Ltd  
Arosyss  
Arosus

if my index contain the following data and i'm going for search  
'Arosuus' on index.then more relevant data that want's to be search  
'Arosus',because five character are matched with 'Arosus'.what query  
mechanism will be applied to search those type of similar or more  
relevant words.

Thanks

On Sep 5, 5:31 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> > Thanks for reply.can you please explain how keyword analyzer will help  
> > me.fot getting desire result.
> 
> I think that your field does not contain human words (a sentence in fact) but  
> some keywords from your application.  
> That's why, for that same need, I use my self a keyword analyzer on that field.

> So, Lucene does not try to make tokens from the field and let it as it is.  
> BTW, if you want to search for abcd (and not ABCD), you will have probably to  
> add a lowercase filter.
> 
> Something like :  
> curl -X PUThttp://localhost:9200/myindex/-d '  
> {  
> "settings":{  
> "index":{  
> "analysis":{  
> "analyzer":{  
> "key\_lowercase":{  
> "tokenizer":"keyword",  
> "filter":"lowercase"  
> }  
> }  
> }  
> }  
> }}
> 
> '
> 
> curl -X PUThttp://localhost:9200/myindex/mytype/\_mapping-d '  
> {  
> "mytype":{  
> "properties":{  
> "myfield":{  
> "analyzer":"key\_lowercase",  
> "type":"string"  
> }  
> }  
> }}
> 
> '
> 
> After setting your mapping for that field, you will be able to perform a prefix  
> search or a term search or a wildcard (cost more).
> 
> HTH
> 
> --  
> David Pilatohttp://dev.david.pilato.fr/  
> Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 5, 2011, 3:05pm UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311/6 "2011-09-05T15:05:01Z")

</div>

Did you look atFuzzy Queries ?  
[http://www.elasticsearch.org/guide/reference/query-dsl/fuzzy-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/fuzzy-query.html)

I did not start to use it myself, but perhaps it can help you.

David.

---

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [September 6, 2011, 7:36am UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311/7 "2011-09-06T07:36:44Z")

</div>

Thanks for reply.I use fuzzy query, i have made following setting:

```
SearchResponse searchResponse = client.prepareSearch(indexName)
   .setSearchType(SearchType.DEFAULT)
   .setQuery(fuzzyQuery(indexColumn,data.toLowerCase()).minSimilarity(0).prefixLength(30))
   .execute()
   .actionGet();

```

## search issue with fuzzy query :

1.) if my search data "IBM " is on caps it doesn't search but if i  
give it lowercase is search nicely.  
2.) when i go for search "Arosys Technologies" it got zero hit(tried  
both lowercase and uppercase),that means it can't search if data  
contain white space.  
3.) if search data "Arosuus" then hit found zero hit (tried both  
lowercase and uppercase) and expected result may be "Arosus".  
4.) Is there is any method to get Similarity count when searching  
data using fuzzy query.

please help me to resolve above define issues, any help will be  
appreciated.

Thanks

On Sep 5, 8:05 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> Did you look atFuzzy Queries ?[Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/fuzzy-query.html)
> 
> I did not start to use it myself, but perhaps it can help you.
> 
> David.

---

<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:55am UTC](https://discuss.elastic.co/t/how-to-boosting-a-term-using-java-api/5311/8 "2017-07-06T03:55:10Z")

</div>


