ES - how to give priority to keyword in the tokenizer filter

Hello There,

I am using ES 6.1.1 Tokenized Standard filter in C# with NEST Query in the following way.

client.CreateIndex(indexName, c => c
.Settings(s => s.NumberOfShards(1)
.Analysis(a => a
.CharFilters(cf => cf
.Mapping("programming_language", mca => mca
.Mappings(new[]
{
"c# => csharp",
"C# => Csharp"
})
)
)
.Analyzers(anc => anc
.Custom("Tokenized_Filter", ca => ca
.CharFilters("html_strip", "programming_language")
.Tokenizer("standard")
.Filters("standard", "lowercase", "stop")
)
)
)
)

For fetching data from elastic search, I am suing following Query:

q.ConstantScore(cs => cs.Filter(wc => wc.Field(f => f.Name.Suffix("Tokenized")).Value(directoryReqFltVm.Name ))).Boost(40))

when I search for Ex "XYZ Community", the tokenized filter search for "XYZ" and give the boost of 40, then search "Community" and gives an equal boost of 40
I want that It should give more priority to the first keyword than to second so that more relevant data should come up first in searching

Is there is any solution for this or i can write my own custom filter which should help me in achieving that

any help would be really appreciated.

thanks in advance

Regards
Shivam

"First" meaning the first token in whatever query the user sends?

You could do that by adding a custom analyzer which has a limit_token_count token filter set to 1. That will save the first token. When querying, you can query both the "limited" field as well as the regular field, and boost the "limited" field so it has a higher score.

Hello Polyfractal

Thanks for the help
Can you please provide some Example for the same, as it is very difficult to understand with this info.
Thanks in advance

Regards
Shivam

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.