作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 elasticsearch-6.1.1。由于 CreateIndexRequest api 不是由 JavaHighLeve client-6.1.1 提供的,我尝试通过使用此处给出的 TransportClient 来创建索引:( https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/_changing_the_application_8217_s_code.html )代码是:
public class IndexOperations {
RestHighLevelClient client ;
public IndexOperations(RestHighLevelClient client){
this.client = client ;
}
public void indexOperations()throws UnknownHostException,IOException {
TransportClient transportClient = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"),9300));
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("delllogfiles")
.startObject("properties")
.startObject("message")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("logid")
.field("type","long")
.endObject()
.startObject("version")
.field("type","long")
.endObject()
.startObject("qualifiers")
.field("type","text")
.endObject()
.startObject("level")
.field("type","long")
.endObject()
.startObject("task")
.field("type","long")
.endObject()
.startObject("opcode")
.field("type","long")
.endObject()
.startObject("keywords")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("recordid")
.field("type","long")
.endObject()
.startObject("providername")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("providerid")
.field("type","long")
.endObject()
.startObject("logname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("processid")
.field("type","long")
.endObject()
.startObject("threadid")
.field("type","long")
.endObject()
.startObject("machinename")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("userid")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("timecreated")
.field("type","date")
.endObject()
.startObject("activityid")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("relatedactivityid")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("containerlog")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("matchedqueryids")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("bookmark")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("levldispalyname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("opcodedisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("taskdisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("keywordsdisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("properties")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject()
.string();
CreateIndexResponse createIndexResponse = transportClient.admin().indices()
.prepareCreate("logfiles")
.addMapping("delllogfiles",mapping,XContentType.JSON)
.get();
System.out.println("finally index created "+createIndexResponse.isAcknowledged());
transportClient.close();
当运行代码时,我得到一个异常:
Exception in thread "main" MapperParsingException[Failed to parse mapping [delllogfiless]: Could not convert [message.index] to boolean]; nested: IllegalArgumentException[Could not convert [message.index] to boolean]; nested: IllegalArgumentException[Failed to parse value [not_analyzed] as only [true] or [false] are allowed.];
如何在使用 TransportClient 时将字段的分析器设置为 not_analyzed?
最佳答案
来自elastic search 5的索引属性只有两个选项
对于 not_analyzed 字符串字段,使用字段类型 keyword 而不是默认为 not_analyzed 的 text
这是它的链接。 https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html
关于elasticsearch - 使用 Transport Client 创建索引时,我应该如何将字段的分析指定为 not_analyzed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48472963/
我是一名优秀的程序员,十分优秀!