How to boosting a term using java API?


(Sam-4) #1

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


(David Pilato) #2

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

Boosting won't help you in that case.

HTH
David :wink:

Le 5 sept. 2011 à 08:54, sam 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


(Sam-4) #3

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 wrote:

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

Boosting won't help you in that case.

HTH
David :wink:

Le 5 sept. 2011 à 08:54, sam 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


(David Pilato) #4

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/ -d '
{
"settings":{
"index":{
"analysis":{
"analyzer":{
"key_lowercase":{
"tokenizer":"keyword",
"filter":"lowercase"
}
}
}
}
}
}
'

curl -X PUT 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/
Twitter : @dadoonet


(Sam-4) #5

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" 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


(David Pilato) #6

Did you look atFuzzy Queries ?
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.


(Sam-4) #7

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" da...@pilato.fr wrote:

Did you look atFuzzy Queries ?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.


(system) #8