fuzziness in elastic search search by letter not by word - elasticsearch

Hey I am trying to make a fuzzy search in Elasticsearch I write this query
"query": {
"match": {
"NAME": {
"query": "data" ,
"fuzziness": "AUTO"
}
}
}
but it keeps return the best match on word not the nearest letter
what I need is actually near to google search any idea ?

Related

Why does it match on part of a word but not the whole word?

I have an index with documents with the name property. My target document has the following value : "name" : "Eiker Football Team Crows". There are quite a few with "Eiker" somewhere in their name as it is a region. Searches for Football Team finds this document and so does eik football team or even eike (though it finds others too). What is really weird is that Eiker finds NONE of the documents with the word, but does suggest some with permutations like Eker or Eikeland. Literally searching for the full correctly spelled and cased name as the document I am looking for, does NOT find it.
This is the search I am trying to do as written in Kibana developer:
GET orgs/_search
{
"query": {
"match": {
"name": {
"query": "eiker",
"operator": "and",
"fuzziness": "auto",
"max_expansions": 5,
"prefix_length": 0
}
}
}
}
Why does my Elastic search hate r?
I have tried different values of expansions or prefixes. Or or instead of and operator.
Simple answer of your question is you are using fuzziness so it will do the fuzzy matching as well. Please check this documentation.
fuzziness allows fuzzy matching based on the type of field being
queried.
Also, Elasticsearch return top 10 result only by default. If you want to get more result then set size param value to large number.
Update:
As per your comment, you are using autocomplete as index time analyzer and autocomplete_search as search time analyzer so thats why result are not coming. Try the below query with same analyzer which is use at index time for name field and it should return result. (Please add your index mapping and analyzer setting in question so it will easy to answer question)
POST sampleindex/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": {
"query": "Eiker",
"operator": "and",
"fuzziness": "auto",
"max_expansions": 5,
"prefix_length": 0,
"analyzer": "autocomplete"
}
}
}
]
}
}
}

Elasticsearch: how to write bool query that will contain multiple conditions on the same token?

I have a field with tokenizer that splits by dots.
on search, the following value aaa.bbb will be splitted to two terms aaa and bbb.
My question is how to write bool query that will contain multiple conditions on the same term?
For example, i want to get all docs where its field contains a term that matches a fuzzy search for gmail but also the same term must not contain gamil.
Here are some examples of what i want to achieve:
bmail // MATCH: since its matches fuzzy search and is not gamil
gamil.bmail // MATCH: since the term bmail matches fuzzy search and is not gamil
gamil // NO MATCH: since its matches fuzzy search and but equals gamil
NOTE: the following query does NOT appear to be working since it looks as if one term matches one condition and the second term matches the other, it will be considered a hit.
{
...
"body": {
"query": {
"bool": {
"must": [
{
"fuzzy": {
"my_field": {
"value": "gmail",
"fuzziness": 1,
"max_expansions": 2100000000
}
}
},
{
"bool": {
"must_not": [
{
"query_string": {
"default_field": "my_field",
"query": "*gamil*",
"analyzer": "keyword"
}
}
]
}
}
]
}
}
},
}
I ended up using Highlight by executing fuzzy (or any other) query, and then programatically filter the results by the returned highlight object.
span queries might also be a good option if you don't need regular expression or you can make sure you don't exceed the boolean query limit.
(see more details in the provided link)

ANDing search keywords for elastic Search

How can we configure elastic search so that it only returns results which matches all the words in the search query. The documents indexed have data having multiple fields and so the words of search query may match different fields of data but all the words must get matched in the result ?
you can query string query feature to search for results
sample search query
GET /_search
{
"query": {
"query_string": {
"query": "(content:this OR name:this) AND (content:that OR name:that)"
}
}
}
In this query content and name is the field name, this is the search criteria
you can build search query similar to that.
I think you're looking for a multi_match query together with and operator. This is the link to docs: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html and it seems that cross_fieldsis query type you're looking for. I'd read more on that page, but this is probably what you are looking for:
GET /_search
{
"query": {
"multi_match" : {
"query": "Will Smith",
"type": "cross_fields",
"fields": [ "first_name", "last_name" ],
"operator": "and"
}
}
}

AND between tokens in elasticsearch

When I'm trying to search for a documents with such query (field indexed with Standard analyzer):
"query": {
"match": {
"Book": "OG/44"
}
}
I've got terms 'OG' and '44' and the result set will contain results where could be either of these terms. What analyzer/tokenizer I should use to get results when only both of terms are present?
You can set operator in match query (by default it is or)
"query": {
"match": {
"Book": {
"query": "OG/44",
"operator" : "and"
}
}
}
You have two tokens because standard analyzer tokenized them by slash, so if you need not this behaviour you can escape it

Difference between Fuzzy and Match in Elasticsearch

I wanna know the difference between the kind of search in Elasticsearch: Fuzzy and Match
I mean the advantages and disadvantages of each one, If anyone is better.
Thanks in advance.
Fuzzy can help you search within a term, match will match a whole term.
Take this example:
POST index1/test1
{
"field1": "this is a full on sentence"
}
Fuzzy will match part of a term (each word is a term)
GET index1/test1/_search
{
"query": {
"fuzzy": {
"field1": "ull"
}
}
}
Term match will not find the record because "ull" is not a full term.
GET index1/test1/_search
{
"query": {
"match": {
"field1": "ull"
}
}
}

Resources