java es1.8_Java api 怎样使用分词es 5.6.3

在Java环境下,使用Elasticsearch 5.6.4和Spring Boot 2.0.0.M6,作者遇到在创建并配置了`orderDetailList.productName`字段为`ik_max_word`分词器后,执行AnalyzeRequestBuilder时遇到`no such index`错误。代码中展示了如何创建索引和mapping,以及尝试执行分析请求的部分。问题可能源于索引未正确创建或未在执行分析请求时指定正确的索引名。
摘要由CSDN通过智能技术生成

我先描述一下我的环境:

JDK:1.8

Elasticsearch: 5.6.4

spring boot: 2.0.0.M6

部分代码:

1.这个是我对改字段进行创建,存储,索引,类型为string,创建用分词ik_max_word,查询时候用:searchAnalyzer

用heads插件查询mapping如下:

{

"tianlian_order_index": {

"mappings": {

"order": {

"properties": {

"customerUserId": {

"type": "text",

"store": true

},

"deliverType": {

"type": "text",

"store": true

},

"orderDetailList": {

"properties": {

"activeId": {

"type": "text",

"store": true

},

"productName": {

"type": "text",

"store": true,

"analyzer": "ik_max_word"

}

}

},

"orderId": {

"type": "text",

"store": true

},

"orderStatus": {

"type": "text",

"store": true

}

}

}

}

}

}

2.使用的时候代码如下:

我先描述一下我的环境:

JDK:1.8

Elasticsearch: 5.6.4

spring boot: 2.0.0.M6

部分代码:

1.这个是我对改字段进行创建,存储,索引,类型为string,创建用分词ik_max_word,查询时候用:searchAnalyzer

用heads插件查询mapping如下:

{

"tianlian_order_index": {

"mappings": {

"order": {

"properties": {

"customerUserId": {

"type": "text",

"store": true

},

"deliverType": {

"type": "text",

"store": true

},

"orderDetailList": {

"properties": {

"activeId": {

"type": "text",

"store": true

},

"productName": {

"type": "text",

"store": true,

"analyzer": "ik_max_word"

}

}

},

"orderId": {

"type": "text",

"store": true

},

"orderStatus": {

"type": "text",

"store": true

}

}

}

}

}

}

2.使用的时候代码如下:

我先描述一下我的环境:

JDK:1.8

Elasticsearch: 5.6.4

spring boot: 2.0.0.M6

部分代码:

1.这个是我对改字段进行创建,存储,索引,类型为string,创建用分词ik_max_word,查询时候用:searchAnalyzer

用heads插件查询mapping如下:

{

"tianlian_order_index": {

"mappings": {

"order": {

"properties": {

"customerUserId": {

"type": "text",

"store": true

},

"deliverType": {

"type": "text",

"store": true

},

"orderDetailList": {

"properties": {

"activeId": {

"type": "text",

"store": true

},

"productName": {

"type": "text",

"store": true,

"analyzer": "ik_max_word"

}

}

},

"orderId": {

"type": "text",

"store": true

},

"orderStatus": {

"type": "text",

"store": true

}

}

}

}

}

}

2.使用的时候代码如下:

AnalyzeRequestBuilder request = new AnalyzeRequestBuilder(elasticsearchTemplate.getClient(), AnalyzeAction.INSTANCE, "orderDetailList.productName",orderDTO.getContent()); request.setTokenizer("ik_max_word"); List tokens = request.execute().actionGet().getTokens(); System.out.println("tokens:"+tokens);

3.但一直报结果no such index 是使用的方法不对吗?

2017-11-22 11:38:12.709  INFO 14468 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 26 ms

2017-11-22 11:38:21.902 ERROR 14468 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is [orderDetailList.productName] IndexNotFoundException[no such index]] with root cause

org.elasticsearch.index.IndexNotFoundException: no such index

at org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndices(IndexNameExpressionResolver.java:186)

at org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndices(IndexNameExpressionResolver.java:122)

at org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteSingleIndex(IndexNameExpressionResolver.java:243)

at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$AsyncSingleAction.(TransportSingleShardAction.java:146)

at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$AsyncSingleAction.(TransportSingleShardAction.java:123)

at org.elasticsearch.action.support.single.shard.TransportSingleShardAction.doExecute(TransportSingleShardAction.java:95)

at org.elasticsearch.action.support.single.shard.TransportSingleShardAction.doExecute(TransportSingleShardAction.java:59)

at org.elasticsearch.action.support.TransportAction.doExecute(TransportAction.java:146)

at org.elasticsearch.action.support.TransportAction$RequestFilterChain.proceed(TransportAction.java:170)

at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:142)

at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:84)

at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$TransportHandler.messageReceived(TransportSingleShardAction.java:265)

at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$TransportHandler.messageReceived(TransportSingleShardAction.java:259)

at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)

at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69)

at org.elasticsearch.transport.TcpTransport$RequestHandler.doRun(TcpTransport.java:1539)

at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)

at org.elasticsearch.common.util.concurrent.EsExecutors$1.execute(EsExecutors.java:110)

at org.elasticsearch.transport.TcpTransport.handleRequest(TcpTransport.java:1496)

at org.elasticsearch.transport.TcpTransport.messageReceived(TcpTransport.java:1379)

at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.channelRead(Netty4MessageChannelHandler.java:74)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)

at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)

at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:297)

at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:413)

at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)

at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)

at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:241)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)

at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)

at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)

at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)

at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:544)

at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:498)

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)

at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)

at java.lang.Thread.run(Thread.java:745)

请求正解哦。谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值