Fuzzy contains query with elasticSearch -
how can perform query fuzzy , contains on strings? let's have following document:
{ ... "name":"william shakespeare" ... }
i receive document following queries:
- "william" (will return williams)
- "willeam" (same 1)
- "william shake" (will return document contains "william shake"
- "wiliam sake" (same 3)
- "william shakespeare" / "william shakespeare" / "william shakespeer" (will return william shakespeare
i tried use ngram analyzer , fuzziness queries no success.
{ "settings": { "analysis": { "filter": { "ngram_analyzer_filter": { "type": "ngram", "min_gram": 2, "max_gram": 15 } }, "analyzer": { "ngram_analyzer": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "ngram_analyzer_filter" ] } } } }, "mappings": { "my_type": { "properties": { "name": { "type": "string", "analyzer": "ngram_analyzer", "search_analyzer": "standard", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } } } } }
my query:
{ "query": { "multi_match": { "query": "william shake", "fields": [ "name.raw" ], "fuzziness": 2, "minimum_should_match":2 } } }
- it multi_match because search more 1 field.
- tried use analyzed field or not_analyzed field.
- tried use "type":"phrase"
- elastic version 2.3.1
try below query.
{ 'query': { 'multi_match': { 'fields': [ "name.raw" ], 'query': $scope.search.queryterm, 'fuzziness': 2, 'prefix_length': 1 } } }
Comments
Post a Comment