简体   繁体   English

Elasticsearch Analyzer忽略连字符

[英]Elasticsearch Analyzer that ignores hyphen

We are in the process of implementing Elasticsearch and using .Nest in a .NET solution. 我们正在实施Elasticsearch并在.NET解决方案中使用.Nest We've created and loaded an index having several fields. 我们创建并加载了一个包含多个字段的索引。 We wish to define and analyzer that will produce the same search results for an itemNumber field when the user enters UNV-1234 or UNV1234 . 我们希望定义和分析器在用户输入UNV-1234UNV1234时将对itemNumber字段产生相同的搜索结果。 The itemNumber field is limited to item number only with no additional words. itemNumber字段仅限于项目编号,没有其他单词。 However the item number field may have a number separated by a space. 但是,项目编号字段的编号可以用空格分隔。

Based on my searches, it seems that the keyword analyzer would provide the desired results. 根据我的搜索,关键字分析器似乎可以提供所需的结果。 This is not working for us. 这对我们不起作用。

Can someone provide information on how best to accomplish this? 有人可以提供有关如何最好地完成此任务的信息吗?

"itemNumber": {
    "type": "string",
    "index": "not_analyzed",
    "fields": {
        "_english": {
        "type": "string",
        "analyzer": "english"
        },
        "_keyword": {
        "type": "string",
        "analyzer": "keyword"
        },
        "_standard": {
        "type": "string",
        "analyzer": "standard"
        }
    }
}

You need to define a custom analyzer with "keyword" tokenizer and a pattern replace token filter to remove any special character and use it for your field. 您需要使用“关键字”令牌生成器和模式替换令牌过滤器定义自定义分析器,以删除任何特殊字符并将其用于您的字段。 The analyzer can be defined as below 分析仪可以定义如下

    "analysis" : { 
        "filter" : { 
            "cleanspecial": { 
                "type": "pattern_replace", 
                "pattern": "[^a-zA-Z0-9]", 
                "replacement": "" 
            } 
        }, 
        "analyzer" : { 
            "cleanspecialanalyzer": { 
                "filter": ["cleanspecial"], 
                "type": "custom", 
                "tokenizer": "keyword" 
             }
         }
    }

Note: Please verify the pattern, I haven't tested it. 注意:请验证模式,我尚未测试。

You can change the mapping as below 您可以如下更改映射

"itemNumber": {
    "type": "string",
    "index": "not_analyzed",
    "fields": {
        "_english": {
        "type": "string",
        "analyzer": "english"
        },
        "_keyword": {
        "type": "string",
        "analyzer": "cleanspecialanalyzer"
        },
        "_standard": {
        "type": "string",
        "analyzer": "standard"
        }
    }
}

Search can happen on the field itemNumber._keyword 搜索可以在字段itemNumber._keyword上进行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Elasticsearch 5中更改映射属性分析器 - Change mapping property analyzer in Elasticsearch 5 ElasticSearch-字典的空白分析器<object, object> - ElasticSearch - Whitespace analyzer for Dictionary<object, object> .NET ElasticSearch NEST - 用于部分匹配的多个字段的 NGram 分析器 - .NET ElasticSearch NEST - NGram Analyzer on Multiple Fields for Partial Matches Elasticsearch Nest C#— ElasticProperty Analyzer导致动态映射 - Elasticsearch Nest C# — ElasticProperty Analyzer causing dynamic mapping ElasticSearch Nest的IndexSettings分析为空。 如何添加自定义分析器? - IndexSettings Analysis of ElasticSearch Nest is null. How to add custom Analyzer? C#NEST ElasticSearch Default_Search分析器 - C# NEST ElasticSearch Default_Search analyzer 使用NEST在ElasticSearch的IEnumerable属性上配置分析器的问题 - Issue configuring analyzer on a IEnumerable property for ElasticSearch using NEST 在文本字段上使用 Nest Analyzer“关键字”而不访问 ElasticSearch DB - Using Nest Analyzer “keyword” on text Field without access to ElasticSearch DB 当搜索关键字包含连字符时,仍会分析以属性“not_analyzed”提交的弹性搜索NEST客户端 - elasticsearch NEST client, filed with attribute “not_analyzed” still be analyzed when search keywords contains hyphen 如何使用自定义分析器创建ElasticSearch NEST v.5客户端的索引? - How to create index of ElasticSearch NEST v.5 client by using custom analyzer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM