similarity - ElasticSearch Analyzer on text field -
here field on elasticsearch :
"keywordname": { "type": "text", "analyzer": "custom_stop" } here analyzer :
"custom_stop": { "type": "custom", "tokenizer": "standard", "filter": [ "my_stop", "my_snow", "asciifolding" ] } and here filters :
"my_stop": { "type": "stop", "stopwords": "_french_" }, "my_snow" : { "type" : "snowball", "language" : "french" } here documents index (in field : keywordname) :
"canne peche", "canne", "canne peche telescopique", "iphone 8", "iphone 8 case", "iphone 8 cover", "iphone 8 charger", "iphone 8 new"
when search "canne", gives me "canne" document, want :
get ads/_search { "query": { "match": { "keywordname": { "query": "canne", "operator": "and" } } }, "size": 1 } when search "canne à pêche", gives me "canne peche", ok, too. same "cannes à pêche" -> "canne peche" -> ok.
here tricky part : when search "iphone 8", gives me "iphone 8 cover" instead of "iphone 8". if change size, set 5 (as returns 5 results containing "iphone 8"). see "iphone 8" 4th result in term of score. first "iphone 8 cover" "iphone 8 case" "iphone 8 new" , "iphone 8" ...
here result of query :
{ "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 5, "max_score": 1.4009607, "hits": [ { "_index": "ads", "_type": "keyword", "_id": "iphone 8 cover", "_score": 1.4009607, "_source": { "keywordname": "iphone 8 cover" } }, { "_index": "ads", "_type": "keyword", "_id": "iphone 8 case", "_score": 1.4009607, "_source": { "keywordname": "iphone 8 case" } }, { "_index": "ads", "_type": "keyword", "_id": "iphone 8 new", "_score": 0.70293105, "_source": { "keywordname": "iphone 8 new" } }, { "_index": "ads", "_type": "keyword", "_id": "iphone 8", "_score": 0.5804671, "_source": { "keywordname": "iphone 8" } }, { "_index": "ads", "_type": "keyword", "_id": "iphone 8 charge", "_score": 0.46705723, "_source": { "keywordname": "iphone 8 charge" } } ] } } how can keep flexibility concerning keyword "canne peche" (accents, capital letters, plural terms) tell him if there exact match ("iphone 8" = "iphone 8"), give me exact keywordname ?
i suggest this:
"keywordname": { "type": "text", "analyzer": "custom_stop", "fields": { "raw": { "type": "keyword" } } } and query:
{ "query": { "bool": { "should": [ { "match": { "keywordname": { "query": "iphone 8", "operator": "and" } } }, { "term": { "keywordname.raw": { "value": "iphone 8" } } } ] } }, "size": 10 }
Comments
Post a Comment