这就是我映射索引的方式。
settings = new ConnectionSettings(pool)
.DefaultIndex(defaultIndex)
.MapDefaultTypeNames(m => m.Add(typeof(MyClass), "content"))
.PrettyJson()
.DisableDirectStreaming());
可以说我有一个文档索引到ES
content: "Tim Cook revealed during the earnings call that iPhone sales in India grew by 56% on a yearly basis, despite the company's first global sales decline in 13 years."
现在,如果用户使用匹配查询搜索单词
{
"query": {
"match": {
"answer": {
"query": "decline"
}
}
}}
说我得到0.047分。
但是,使用相同的查询,如果我搜索单词“下降” ,则得到0分。我想检查该单词是否部分存在于文档中。我怎样才能做到这一点?
最佳答案
您需要通过声明一个特定的分析器来分析内容字段来定义字段映射。在这种情况下,我们可以使用 english
language analyzer,它将根据英语语法和词汇规则来阻止标记。
PUT your_index
{
"mappings": {
"your_type": {
"properties": {
"content": {
"type": "string",
"analyzer": "english"
}
}
}
}
}
然后您可以索引您的内容
PUT /your_index/your_type/1
{
"content": "Tim Cook revealed during the earnings call that iPhone sales in India grew by 56% on a yearly basis, despite the company's first global sales decline in 13 years."
}
最后,您可以同时搜索
decline
和declining
并获得相同的分数POST /your_index/_search
{
"query": {
"match": {
"content": {
"query": "decline"
}
}
}
}
POST /your_index/_search
{
"query": {
"match": {
"content": {
"query": "declining"
}
}
}
}
关于c# - ElasticSearch中的单词匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36904843/