How to extract the Exact strings or 80% of matched strings from elastic search

HI guys,

Actually i want to build an suggestion box, for that i need to suggest the exact String or equivalent to 80% matched strings only.. I have used Auto complete filter, it is providing more irrelevant data to search. So please help me to build an suggestion box.

It's hard to tell what is wrong without seeing what you did so far. Anyway look at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html

This are the index settings::
curl -XPUT 'localhost:9200/locations?pretty' -H 'Content-Type: application/json' -d'
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 3,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
}
mappings:::
curl -XPUT 'localhost:9200/locations/_mapping/locations?pretty' -H 'Content-Type: application/json' -d'
{
"locations": {
"properties": {
"country": {
"type": "text",
"analyzer": "autocomplete"
}
}
}
}'

query structure::
elasticserver.client.search({
index: locations,
type: locations,
body: {
query: {
bool: {
should: [{
match: {
country: input
}
}]
}

            },
           
            _source: ["country", "country_id", "type"]
        }
    }

Actually this giving results by matching input string with words present in sentences..Example:: while i am trying to get "india" related data it is giving indo-tibettan,indonesia etc...
but i want to get exact matched string data.

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

Anyway, add in your mapping a search_analyzer: simple for the field you want to search on.

I am getting same set of results after adding "search_analyzer: simple" in mappings also..
I have another doubt can we extract exact matched data without applying any analysers?
Thanks in Advance

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem.

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