Prioritize exact match using nGram

Hello All,

I am wondering how to rank exact match higher than the nGram matches.

For example:

search string: abcd
results - abcd, abcde, abcdegl

not in a particular order.

But I want to rank 'abcd' higher than the rest. Is it possible??
I am adding my mappings, analyzers and query below.

mapping for a particular field:

{
'type': 'multi_field',
'fields': {
'name': {
'type': 'string',
'search_analyzer': 'search_analyzer',
'index_analyzer': 'index_analyzer',
'include_in_all': True
},
'untouched': {
'type': 'string',
'index': 'not_analyzed',
'include_in_all': False,
},
'standard': {
'type': 'string',
'analyzer': 'search_analyzer',
'include_in_all': False
}
},
}

My analyzers:

{
'settings': {
'analysis': {
'filter': {
'substring': {
'type': 'nGram',
'min_gram': 1,
'max_gram': 25
}
},
'analyzer': {
'index_analyzer': {
'type': 'custom',
'tokenizer': 'standard',
'filter': [
'standard',
'lowercase',
'asciifolding',
'substring'
]
},
'search_analyzer': {
'type': 'custom',
'tokenizer': 'standard',
'filter': [
'standard',
'lowercase',
'asciifolding'
]
}
}
}
}
}

query (I am searching in all fields'_all')

{
'query': {
'query_string': {
'query': 'abcd',
'analyze_wildcard': True,
'analyzer': 'search_analyzer',
'default_operator': 'AND'
}
},
}

Thanks,
Nikhil

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3bd861ff-d854-45ab-bb4f-471a7d34b8cc%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Nikhil,

Try to take a look at the function_score query. You should be able to
inject a function with say a term filter and provide an override
(script_score) or boost (boost_factor) to perform the exact match boosting.

On Wednesday, January 22, 2014 11:07:18 PM UTC-5, Nikhil Podduturi wrote:

Hello All,

I am wondering how to rank exact match higher than the nGram matches.

For example:

search string: abcd
results - abcd, abcde, abcdegl

not in a particular order.

But I want to rank 'abcd' higher than the rest. Is it possible??
I am adding my mappings, analyzers and query below.

mapping for a particular field:

{
'type': 'multi_field',
'fields': {
'name': {
'type': 'string',
'search_analyzer': 'search_analyzer',
'index_analyzer': 'index_analyzer',
'include_in_all': True
},
'untouched': {
'type': 'string',
'index': 'not_analyzed',
'include_in_all': False,
},
'standard': {
'type': 'string',
'analyzer': 'search_analyzer',
'include_in_all': False
}
},
}

My analyzers:

{
'settings': {
'analysis': {
'filter': {
'substring': {
'type': 'nGram',
'min_gram': 1,
'max_gram': 25
}
},
'analyzer': {
'index_analyzer': {
'type': 'custom',
'tokenizer': 'standard',
'filter': [
'standard',
'lowercase',
'asciifolding',
'substring'
]
},
'search_analyzer': {
'type': 'custom',
'tokenizer': 'standard',
'filter': [
'standard',
'lowercase',
'asciifolding'
]
}
}
}
}
}

query (I am searching in all fields'_all')

{
'query': {
'query_string': {
'query': 'abcd',
'analyze_wildcard': True,
'analyzer': 'search_analyzer',
'default_operator': 'AND'
}
},
}

Thanks,
Nikhil

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5cdcf8ca-6688-46f5-b897-29a258accc45%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.