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");
Related
I understand that the ElasticSearch phrase suggester can get suggestions for terms based on a field of a document but what happens when that word doesn't exist in the text of a document? Is it possible to hook up the phrase suggester to a custom dictionary in addition to using the text from the document?
You can just create a document manually inject these values into the same index and same field. Also make sure your search does not consider these documents for search.
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
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.
In my index I have inserted fields without changing the case of values(Upper case or Lower case), like in my elasticsearch document a field name contains value Hello World. And i have made name field as not_analyzed for exact match. But in that case, when i search by hello world this document don’t returned by elasticsearch, might be due to case sensitivity. I have tried by using term query and match query but haven't found a luck.
Please suggest, if there is a way.
Thanks
The only way you can do this in Elasticsearch is by analyzing the field and using token filters. There is a lowercase token filter available that you should use but this can't really be done on-the-fly like SQL where you wrap the field to be queried against in something like LOWER().
To get the effect you desire I would use something like the Keyword tokenizer with the Lowercase token filter. If you set this analyzer to be the default analyzer for indexing and searching then your searches will also be case insensitive too.
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.