Elasticsearch multi match exact match boosting - elasticsearch

We use spring data elastic search.
We use multimatch query to search against multiple fields.
QueryBuilder queryBuilder = multiMatchQuery(searchInput, "id","firstName","lastName","title","nickName","location")
.type(MatchQueryBuilder.Type.PHRASE_PREFIX).analyzer("standard");
We use PHRASE_PREFIX for phrase match.
Now, we would like to add boosting for exact match on nickName( boosting only if exact match ).
For example, when i search for Phone, if there is a exact match on nickName, it should be ordered first in the result. If there is no exact match, then firstName should be given boosting. I tried boosting like below.
QueryBuilder queryBuilder = multiMatchQuery(searchInput, "id","firstName","lastName","title","nickName^9","location")
.type(MatchQueryBuilder.Type.PHRASE_PREFIX).analyzer("standard");
Boosting doesnt seem to be working. Also not sure, how to add boosting only on exact match on a field.
Thanks

Related

ElasticSearch: term vs match query decision

Being new to ElasticSearch, need help in my understanding.
What I read about term vs match query is that term query is used for exact match and match query is used when we are searching for a term and want result based on a relevancy score.
But if we already defined a mapping for a field as a keyword, why anyone has to decide upon between term vs match, wouldn't it be always a term query in case mapping is defined as a keyword?
What are the use cases where someone will make a match query on the keyword mapping field?
The same confusion is vice versa.
A text field will be analyzed (transformed, split) to generate N tokens, and the keyword itself will become a token with no transformations. At the end, you have N tokens referencing a document.
Then.
By doing a match query, you will treat your query as a text as well, by analyzing it before performing the matching (transforming it), and the term will not.
You can create a field with a term mapping, but then perform a match query on top of it (for example if you want to be case insensitive), and you can create a text mapping for a n-gram and perform a term query to match exactly what you're asking for.

Schemaless Elasticsearch not analyzed fields

I need to index documents dynamically, thus I am using schemaless mapping for elasticsearch.
But when i search for an exact match for a value like "ABC XYZ" against a string field, I do not get any hits.
Also I need my search to be case insensitive. Is it possible to acheive this, only by making changes while search like by specifying an analyzer.
I am new to elasticsearch so any help would be appreciated.
I found out the answer
QueryBuilder queryBuilder = QueryBuilders.matchPhraseQuery("fieldName", "ABC XYZ");

ElasticSearch highlighting the matched part in query

I'm sending a match query to ElasticSearch and I'm getting back documents whose matching fields have been highlighted. What I'm trying to do is to map a set of documents to the matching substring in query.
For example, assuming I query with "quick brown". I want to map the document "quick silver" to "quick", "brown fox" to "brown" and "mr brown" to "brown".
This is trivial if document fields exactly contain the word in query. But things get messy when I use fuzziness, synonyms, asciifolding etc. In that case, the highlighted parts of search results might not even appear in my search query.
Is is possible to achieve this task without replicating the analyzer logic on my application?
Use the simple query string query instead of the match query when you try to find mapped documents. And set the operator to or. So quick silver as a query will match docs with quick or silver.

What are the differences between fieldquery vs termquery in elasticsearch?

What are the differences and similarities between fieldquery and termquery
FilterBuilders.queryFilter(QueryBuilders.fieldQuery("truckName", "joshi"));
FilterBuilders.queryFilter(QueryBuilders.termQuery("truckName", "joshi"));
Both returning same results.
Please give an examples
A term query is looking for an exact match of a terms field without doing any analysis of the parameter.
It looks like the fieldQuery (from http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-field-query.html) is a simple form of query_string on a specific field, so it would be doing analysis.
The two would act the same for single word "truckName", but the termQuery would be faster.

Favor exact matches over ngram matches in ElasticSearch when mapping

I have partial matching of words working with ngrams. How can I modify the mapping to always favor exact matches over ngram tokens? I do not want to modify the query. One search box will search multiple types, each with their own fields.
For example, lets say I'm searching job titles, one person has a title of "field engineer", the other a title of "engine technician". If a user searches for "engine", I'd want ES to return the latter as more relevant.
I'm using this mapping almost verbatim: https://stackoverflow.com/a/19874785/978622
-Exception: I'm using an ngram with min of 3 and max of 11 instead of edge ngram
Is it possible to apply a boost/function score to an analyzer? If so I'll apply both the "full_name" and "partial_name" analyzers to my index as well and boost the first.
Edit: I'm using ElasticSearch 1.1.1 and Nest 1.0.0 beta
I don't believe there is anyway to apply boosting to an analyzer as you're suggesting.
One thing you can try, is to use the multi field type in your mapping. You could then apply your partial_name analyzer to one version of the field, and your full_name analyzer to the other version.
With this mapping, you could query both fields differently, but combined (perhaps in a bool query), and apply a boost to the query that is being conducted on the full_name analyzed field.

Resources