Reputation: 1314
How can I perform a query that do fuzzy and contains on strings? Let's say I have the following document:
{
...
"name":"william shakespeare"
...
}
I would like to receive the document for the following queries:
I tried to use ngram analyzer and fuzziness queries with 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
}
}
}
Upvotes: 0
Views: 545
Reputation: 1071
Try below query.
{
'query': {
'multi_match': {
'fields': [
"name.raw"
],
'query': $scope.search.queryTerm,
'fuzziness': 2,
'prefix_length': 1
}
}
}
Upvotes: 0