ElasticSearch ::终止索引和文档时发生异常

时间:2018-08-24 09:25:59

标签: elasticsearch

我是ElasticSearch的新手,正在尝试执行他们在主页中提到的示例,我遇到了这个问题-

   public class RewriteRules
{
    public static void RedirectRequests(RewriteContext context)
    {
        var request = context.HttpContext.Request;

        if (request.Path.Value.EndsWith("/", StringComparison.OrdinalIgnoreCase))
        {
            context.HttpContext.Response.Redirect("/Home.html");
        }
        else if(!request.Path.Value.EndsWith(".html", StringComparison.OrdinalIgnoreCase))
        {
            context.HttpContext.Response.Redirect($"{ request.Path.Value }.html");
        }
    }

    public static void ReWriteRequests(RewriteContext context)
    {
        var request = context.HttpContext.Request;            

        if (request.Path.Value.EndsWith(".html", StringComparison.OrdinalIgnoreCase))
        {
            context.HttpContext.Request.Path = context.HttpContext.Request.Path.Value.Replace(".html","");

        }
    }

}

发布请求的网址和正文如下-

URL-> http://localhost:9200/company 身体->

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "unknown setting [index.mappings.employee.properties.age.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "unknown setting [index.mappings.employee.properties.age.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings",
        "suppressed": [
            {
                "type": "illegal_argument_exception",
                "reason": "unknown setting [index.mappings.employee.properties.experience.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
            },
            {
                "type": "illegal_argument_exception",
                "reason": "unknown setting [index.mappings.employee.properties.name.analyzer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
            },
            {
                "type": "illegal_argument_exception",
                "reason": "unknown setting [index.mappings.employee.properties.name.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
            }
        ]
    },
    "status": 400
}

如何解决该错误?

2 个答案:

答案 0 :(得分:1)

JSON主体对象的语法有两个错误:

  1. 节点settings必须只有两个孩子:indexanalysis。节点mappings必须是根级别的。
  2. 字段name的类型string无效,必须为textkeyword。由于您需要分析此字段,因此在您的情况下应为text

所以工作查询应该是这样的:

{
  "settings": {
    "index": {
       "number_of_shards": 1,
       "number_of_replicas": 1
    },
    "analysis": {
      "analyzer": {
        "analyzer-name": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": "lowercase"
        }
      }
    }
  },
  "mappings": {
    "employee": {
      "properties": {
        "age": {
          "type": "long"
        },
        "experience": {
          "type": "long"      
        },
        "name": {
          "type": "text",
          "analyzer": "analyzer-name"
        }
      }
    }
  }
}

答案 1 :(得分:0)

As you mentioned that you are new to Elastic Search, better start with the basic and use the default settings of ElasticSearch. Use the following mapping:

curl -XPUT localhost:9200/company -d '{
    "mappings": {
        "employee": {
            "properties": {
                "age": {"type": "long"},
                "experience": {"type": "long"},
                "name": {"type": "string","index": "not_analyzed"}
            }
        }
    }
}'