# Exact match and fuzziness…What is the good way?

**URL:** <https://discuss.elastic.co/t/exact-match-and-fuzziness-what-is-the-good-way/158679>\
**Category:** Elasticsearch\
**Created:** [November 29, 2018, 3:26am UTC](https://discuss.elastic.co/t/exact-match-and-fuzziness-what-is-the-good-way/158679 "2018-11-29T03:26:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlindCode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/blindcode/32/37561_2.png) [@BlindCode](https://discuss.elastic.co/u/BlindCode)\
**Post date:** [November 29, 2018, 3:26am UTC](https://discuss.elastic.co/t/exact-match-and-fuzziness-what-is-the-good-way/158679/1 "2018-11-29T03:26:44Z")

</div>

Hello, i was invert many hours trying found the best way to create and autocomplete that support a multilanguaje seach of cities. (ES/EN), fuzzieness and get priority for exact match (show this at top of results) but i cant find a good way to make this task.

My current solution work very well in many cases, but when I to find for Roma the first option is "Iasi-East Romania, romania" and Roma italy is the thirty function (is an exact match)

Result Json:

```
[{"_index":"destinations","_type":"doc","_id":"_X80XWcBn2nzTu98N7_F","_score":75.50012,"_source":{"destination_name_en":"Iasi-East Romania","destination_name_es":"Iasi-East Romania","destination_name_pt":"Iasi-East Romania","country_code":"RO","country_name":"ROMANIA","destination_id":7953,"popularity":"0"}},{"_index":"destinations","_type":"doc","_id":"7380XWcBn2nzTu98OMZl","_score":73.116455,"_source":{"destination_name_en":"La Romana","destination_name_es":"La Romana","destination_name_pt":"La Romana","country_code":"DO","country_name":"DOMINICAN REPUBLIC","destination_id":2816,"popularity":"0"}},{"_index":"destinations","_type":"doc","_id":"1X80XWcBn2nzTu98OMZl","_score":71.4391,"_source":{"_index":"destinations","_type":"doc","_id":"8H80XWcBn2nzTu98OMZl","_score":52.018818,"_source":{"destination_name_en":"Rome","destination_name_es":"Roma","destination_name_pt":"Roma","country_code":"IT","country_name":"ITALY","destination_id":6338,"popularity":"0"}}]

```

Right now this is my best solution..

Mapping:

```
'settings' => [ 
	            'analysis' => [ 	
		            'filter' => [
	                    'autocomplete_filter' => [
	                        "type"=> "edge_ngram",
					        "min_gram"=> 1,
					        "max_gram"=> 20,

	                    ]
                	],
		            'analyzer' => [
	                    'autocomplete' => [
	                        "type" => "custom",
	                        'tokenizer' => "standard",
	                        'filter' => ['lowercase', 'asciifolding', 'autocomplete_filter'],
	                    ]
                	],
                	
	            ],   
	        ],
	        'mappings' =>[
            	'doc' => [
			        "properties"=> [
			            "destination_name_en"=> [
			               "type"=> "text",
			               "analyzer"=> "autocomplete",
			               "search_analyzer"=> "standard",

			            ],
			            "destination_name_es"=> [
			               "type"=> "text",
			               "analyzer"=> "autocomplete",
			               "search_analyzer"=> "standard",
			            ],
			            "destination_name_pt"=> [
			               "type"=> "text",
			               "analyzer"=> "autocomplete",
			               "search_analyzer"=> "standard",
			            ],
			            "popularity"=> [
			               "type"=> "integer",
			            ]
			        ]
            	]
	        ]

```

Search:

```
'query' => [
        		"bool" => [
			    	"should" => [	
		    			 [
                            "multi_match"=>[
                                "query"=>$text,
                                "fields"=>[
                                   "destination_name_*"
                                ],
                                "type"=>"most_fields",
                                "boost" => 2
                            ]
                        ],
                        [
                            "multi_match"=>[
                                "query"=>$text,
                                "fields"=>[
                                   "destination_name_*"
                                ],
                                "fuzziness" => "1",
                                "prefix_length"=> 2                                   
                            ]
                        ]
			    	]
	    		]
			]

```

Also, i want add boost to specific destination using her popularity value.

I hope that someone can guide me with an example or direction of which way to go.

I would appreciate it very much

---

<div class="post-metadata">

**Author:** ![zz\_hello](https://avatars.discourse-cdn.com/v4/letter/z/3bc359/32.png) [@zz\_hello](https://discuss.elastic.co/u/zz_hello)\
**Post date:** [November 29, 2018, 5:59am UTC](https://discuss.elastic.co/t/exact-match-and-fuzziness-what-is-the-good-way/158679/2 "2018-11-29T05:59:13Z")

</div>

> [@BlindCode](#):
>
> destination\_name

maybe you can try with "best\_fields",not "most\_fields".or you can give boost to the best match field

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 27, 2018, 5:59am UTC](https://discuss.elastic.co/t/exact-match-and-fuzziness-what-is-the-good-way/158679/3 "2018-12-27T05:59:35Z")

</div>

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