我需要这个结构“nest-> analysis-> analyzer-> filter-> asciifolding”.i意识到from this link。
因为
我正在准备一个带有elasticsearch的现场搜索引擎,我是elasticsearch的新手。将使用此引擎的网站是土耳其语/英语。
在土耳其,我们有土耳其字母,如'ğ','ü','ş','ı','ö','ç'。但是当我们一般搜索时,我们使用字母'g','u','s','i','o','c'。这不是一个规则,但我们通常这样做,像习惯一样思考,我们曾经习惯过。
我的目标是:
ProductName或Category.CategoryName可能包含土耳其语字母(“Eşarp”)或某些可能输入错误并使用英文字母(“Esarp”)编写 Querystring可能包含土耳其语字母(“eşarp”)或不包含(“esarp”) 查询字符串可能有多个单词 应该针对查询字符串搜索每个索引字符串字段(全文搜索) 我的代码是:(不工作)
public static Uri EsNode;
public static ConnectionSettings EsConfig;
public static ElasticClient EsClient;
EsNode = new Uri("http://localhost:9200/");
EsConfig = new ConnectionSettings(EsNode);
EsClient = new ElasticClient(EsConfig);
EsClient.CreateIndex("employeeindex2", ci => ci
.Settings(s => s
.NumberOfShards(1)
.NumberOfReplicas(0)
.Analysis(analysis => analysis
.TokenFilters(tokenfilters => tokenfilters
.AsciiFolding("folding-preserve", ft => ft
.PreserveOriginal()
)
)
.Analyzers(analyzers => analyzers
.Custom("folding-analyzer", c => c
.Tokenizer("standard")
.Filters("standard", "folding-preserve")
)
)
)
)
.Mappings(m => m
.Map<Employee>(mm => mm
.AutoMap()
.Properties(p => p
.String(s => s
.Name(n => n.Name)
.Fields(f => f
.String(ss => ss
.Name("folding")
.Analyzer("folding-analyzer")
)
)
.NotAnalyzed()
)
)
)
)
);
Employee emp = new Employee() { Name = "yılmaz", SurName = "eşarp" };
EsClient.Index<Employee>(emp, idx => idx.Index("employeeindex2"));
Employee emp2 = new Employee() { Name = "ayşe", SurName = "eşarp" };
EsClient.Index<Employee>(emp2, idx => idx.Index("employeeindex2"));
Employee emp3 = new Employee() { Name = "ömer", SurName = "eşarp" };
EsClient.Index<Employee>(emp3, idx => idx.Index("employeeindex2"));
Employee emp4 = new Employee() { Name = "gazı", SurName = "emir" };
EsClient.Index<Employee>(emp4, idx => idx.Index("employeeindex2"));
}
}
public class Employee
{
public string Name { set; get; }
public string SurName { set; get; }
}
我的搜索查询:
namespace Atom.Customer.Service
{
public class SearchCustomerService
: CustomerModuleServiceBase
{
[MainMethod("1.0")]
public SearchCustomerResponseEntity MainMethodV1(SearchCustomerRequestEntity searchCustomerPhrase)
{
var searchCustomerResponse = new SearchCustomerResponseEntity();
var elasticClient = new ElasticSearchClient();
var client = elasticClient.GetClient("employeeindex2");
var searchResults = client.Search(s => s
.AllTypes()
.From(0)
.Size(10)
.Query(q => q.Bool(p => p.Must((m => m
.QueryString(qs => qs
.DefaultField("_all")
.Query(searchCustomerPhrase.Query))))))
);
searchCustomerResponse.TotalCount = searchResults.HitsMetaData.Total;
searchCustomerResponse.Customers = searchResults.Hits.Select(h => h.Source).ToList();
return searchCustomerResponse;
}
}
}