弹性搜索嵌套使用自定义分析创建索引不起作用

问题描述

我在使用 nesT 7.10.1 创建新索引时尝试添加自定义分析,但出现奇怪的错误。我什至尝试了官方 tutorial 中的代码,但仍然遇到相同的错误,这是我使用的代码示例

 var createIndexResponse = client.Indices.Create("questions",c => c
.Settings(s => s
    .Analysis(a => a
        .CharFilters(cf => cf
            .Mapping("programming_language",mca => mca
                .Mappings(new[]
                {
                    "c# => csharp","C# => Csharp"
                })
            )
        )
        .Analyzers(an => an
            .Custom("index_question",ca => ca
                .CharFilters("html_strip","programming_language")
                .Tokenizer("standard")
                .Filters("lowercase","stop")
            )
            .Custom("search_question",ca => ca
                .CharFilters("programming_language")
                .Tokenizer("standard")
                .Filters("lowercase","stop")
            )
        )
    )
)
.Map<Question>(mm => mm
    .AutoMap()
    .Properties(p => p
        .Text(t => t
            .Name(n => n.Body)
            .Analyzer("index_question")
            .SearchAnalyzer("search_question")
        )
    )
));

问题类

public class Question
{
    public string Body { get; set; }
}

我什至尝试使用分析器属性

public class Question
{
    [Text(Analyzer = "index_question",SearchAnalyzer = "search_question")]
    public string Body { get; set; }
}

仍然出现同样的错误,实际错误

Invalid nesT response built from a unsuccessful (400) low level call on PUT: /questions?pretty=true&error_trace=true Audit trail of this API call:
 - [1] BadResponse: Node: http://x:9200/ Took: 00:00:01.7043112 OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request Failed to execute. Call: Status code 400 from: PUT /questions?pretty=true&error_trace=true. ServerError: Type: mapper_parsing_exception Reason: "Failed to parse mapping [properties]: Root mapping deFinition has unsupported parameters:  [body : {search_analyzer=search_question,analyzer=index_question,type=text}]" CausedBy: "Type: mapper_parsing_exception Reason: "Root mapping deFinition has unsupported parameters:  [body : {search_analyzer=search_question,type=text}]"" Request: {"mappings":{"properties":{"body":{"analyzer":"index_question","search_analyzer":"search_question","type":"text"}}},"settings":{"analysis":{"analyzer":{"index_question":{"char_filter":["html_strip","programming_language"],"filter":["lowercase","stop"],"tokenizer":"standard","type":"custom"},"search_question":{"char_filter":["programming_language"],"type":"custom"}},"char_filter":{"programming_language":{"mappings":["c#
=> csharp","C# => Csharp"],"type":"mapping"}}}}} Response: {   "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception","reason" : "Root mapping deFinition has unsupported parameters:  [body : {search_analyzer=search_question,type=text}]","stack_trace" : "MapperParsingException[Root mapping deFinition has unsupported parameters:  [body : ... [Removed exceprtions ]

来自 nesT 的实际 API 请求是

{
"mappings": {
    "properties": {
        "body": {
            "analyzer": "index_question","search_analyzer": "search_question","type": "text"
        }
    }
},"settings": {
    "analysis": {
        "analyzer": {
            "index_question": {
                "char_filter": [
                    "html_strip","programming_language"
                ],"filter": [
                    "lowercase","stop"
                ],"tokenizer": "standard","type": "custom"
            },"search_question": {
                "char_filter": [
                    "programming_language"
                ],"type": "custom"
            }
        },"char_filter": {
            "programming_language": {
                "mappings": [
                    "c# => csharp","C# => Csharp"
                ],"type": "mapping"
            }
        }
    }
}
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...