elasticsearch - 如何使用NEST搜索文本字段 “as is”?

标签 elasticsearch nest

当我像这样索引新文档时:

ElasticClient.Index(product, idx => idx.Index(indexName));

并且我尝试在此字段(这是一个500个字符的文本)上进行搜索/查询,但没有结果。我想搜索类似“687920/1”的内容,该内容为这500个字符。

最佳答案

下面的Elasticsearch示例可能有用

删除pdm索引

DELETE pdm

索引映射
PUT /pdm
{
  "settings":{
    "analysis":{
      "analyzer":{
    "keyword_lowercase_analyzer": {
      "type": "custom",
      "filter": ["lowercase"],
      "tokenizer": "keyword"
    }
      }
    }
  },
  "mappings": {
    "product": {
    "properties": {
    "product_desc": {
      "type": "string",
      "fields": {
        "raw": {
          "type": "string",
          "analyzer": "keyword_lowercase_analyzer"
        },
        "english": {
          "type":     "text",
          "analyzer": "english"
        }
      }
    }
      }
    }
  }
}

索引文档
POST /pdm/product/_bulk
{ "index": { "_id": "111" }}
{ "product_desc": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 687920/1 It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."}
{ "index": { "_id": "112" }}
{ "product_desc": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 6879210/1 It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."}

搜索查询
POST /pdm/_search
{
    "query": {
    "match_phrase": {
       "product_desc": "687920/1"
    }
    }
}

关于elasticsearch - 如何使用NEST搜索文本字段 “as is”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49852421/

相关文章:

elasticsearch - IllegalArgumentException-仅支持<= 256个有限字符串

elasticsearch - 用于.NET的NEST 6.5.4中按脚本的Elastic Search Update API

elasticsearch - bool过滤器的理解

c# - 单元测试Elastic Search Nest客户端-BulkAll

c# - 嵌套对象上的Elasticsearch过滤器范围

amazon-web-services - 在elasticsearch中1个父类型可以有多个子类型吗?

ruby-on-rails - 索引无事件记录的Elasticsearch

c# - Json.Net 中的 "Current error context error is different to requested error"异常

c# - Elasticsearch 中数据继承的最佳方法是什么?

c# - 在Elasticsearch 5中更改映射属性分析器