将自定义分析器添加到plain elasticsearch

时间:2016-06-08 01:53:38

标签: c# elasticsearch lucene nest plainelastic.net

我把自定义分析器放到POSTMAN ..

    {
    "settings": {
        "index": {
            "number_of_shards": "3",
            "number_of_replicas": "1"
        },
        "analysis" : {
          "analyzer" : {
            "ilhee_Custom" : {
                "tokenizer" : "whitespace",
                "filter" : ["lowercase", "my_stoplist", "snowball", "word_delimiter"]
                }
            },
        "filter" : {
            "my_stoplist" : {
                "type" : "stop",
                "stopwords_path" : "stopword_list.txt",
                "remove_trailing" : true
                }
            }
        }
    },
    "mappings": {
        "mc": {
            "properties": {
                "id": {
                    "type": "long"
                },
                "code": {
                    "type": "string"
                },
                "mainclass": {
                    "type": "string",
                    "analyzer": "ilhee_Custom"
                }
            }
        }
    }
}

我想将代码更改为普通弹性搜索(C#代码).. 这是我目前的代码状态...... 我真的想添加自定义过滤器#34; my_stoplist过滤器...自定义停止词列表" 但是......我不知道怎样才能改变......

private static string BuildCompanyMapping()
    {
        return new PlainElastic.Net.Mappings.MapBuilder<mc>()
            .RootObject(typeName: "mc",
                        map: r => r
                .All(a => a.Enabled(false))
                .Dynamic(false)
                .Properties(pr => pr
                    .String(mc => mc.mainclass, f => f.Analyzer(DefaultAnalyzers.snowball))
                    .String(mc => mc.code, f => f.Analyzer(DefaultAnalyzers.whitespace))
                    .Number(mc => mc.id, null)
                )
          )
          .BuildBeautified();

    }
    private static string BuildIndexSettings()
    {
        return new IndexSettingsBuilder()
            .Analysis(als => als
                .Analyzer(a => a
                    .Custom("ilhee_Custom", custom => custom
                        .Tokenizer(DefaultTokenizers.whitespace)
                        .Filter(DefaultTokenFilters.lowercase,DefaultTokenFilters.snowball,DefaultTokenFilters.stop)
                    )
                    .Custom("fulltext", custom => custom
                        .CharFilter(DefaultCharFilters.html_strip)
                        .Tokenizer(DefaultTokenizers.standard)
                        .Filter(DefaultTokenFilters.word_delimiter,
                                DefaultTokenFilters.lowercase,
                                DefaultTokenFilters.stop,
                                DefaultTokenFilters.standard)
                    )
                )                        
            )
            .BuildBeautified();
    }

0 个答案:

没有答案