es创建索引报错java.lang.IllegalArgumentException: mapping source must be pairs of fieldnam
warning:
这篇文章距离上次修改已过316天,其中的内容可能已经有所变动。
java.lang.IllegalArgumentException: mapping source must be pairs of fieldnames and properties definition.
1,导包错误,需要导入client包下的api,直接解决问题

如果导入的为过时的方法,不修复导包,则mapping 方法需要加_doc。
从es官网找到的
request.mapping("_doc",
“{\n” +
" “_doc”: {\n" +
" “properties”: {\n" +
" “message”: {\n" +
" “type”: “text”\n" +
" }\n" +
" }\n" +
" }\n" +
“}”,
XContentType.JSON);
不生效并报错
查看源码,发现mapping的第二个参数,要求必须为 %2==0,改为

request.mapping("_doc", “datetime”, “type=date”);
多个参数
request.mapping("_doc", “datetime”, “type=date”, “string”, “type=text”);
!!! 设置“_doc”!!!