c# - ElasticSearch中的单词匹配

标签 c# elasticsearch nest

这就是我映射索引的方式。

 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."
}

最后,您可以同时搜索declinedeclining并获得相同的分数
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/

相关文章:

elasticsearch - 当数据之间有空格或破折号时,哪个分析器可以获取附加词的结果?

elasticsearch - 无法使用NEST将动态对象插入Elastic Search

c# - 在 MonoDevelop 中获得漂亮的小部件尺寸 (Gtk#)

c# - 通过代码发送数据集时,VS2010 Crystal Reports 要求登录。

c# - 如何从 C# 中的 3x3 单应矩阵获取旋转、平移、剪切

elasticsearch - Elastic Search多字同义词无法按预期工作

elasticsearch - 在Kibana中搜索问号

c# - 如何使用 .NET、C# 和 WPF 检查 Internet 连接

elasticsearch - 如何使用查询来区分字段不存在还是字段存在但其值为空数组?

c# - 使用Elasticsearch.NET重新创建经Elasticsearch过滤的查询