在 Mapping 里面,将 dynamic 参数设置成 strict 可以拒绝索引包含未知字段的文档。 此条 Tips 由 medcl 贡献。

Java api 怎样使用分词es 5.6.3

Elasticsearch | 作者 yqh5566 | 发布于2017年11月22日 | 阅读数:4132

   我先描述一下我的环境:
JDK:1.8
Elasticsearch: 5.6.4
spring boot: 2.0.0.M6
部分代码:
1.这个是我对改字段进行创建,存储,索引,类型为string,创建用分词ik_max_word,查询时候用:searchAnalyzer
<Catch.jpg>
用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
<Catch.jpg>
用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
<Catch.jpg>
用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<AnalyzeToken> 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.<init>(TransportSingleShardAction.java:146)
    at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$AsyncSingleAction.<init>(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)
 
 
请求正解哦。谢谢
 
 
 
已邀请:

jiangtao

赞同来自:

该方法第三个参数应为索引名,而你却传的是"orderDetailList.productName",错误提示已经很明显了,
AnalyzeRequestBuilder request = new AnalyzeRequestBuilder(elasticsearchTemplate.getClient(), AnalyzeAction.INSTANCE, "orderDetailList.productName",orderDTO.getContent()); 

yangbiao

赞同来自:

你们是用springboot集成的Elasticsearch? 求指导,看下你们的pom文件添加的依赖呢

要回复问题请先登录注册