Servlets 使用servlet连接到Elasticsearch
我不明白,如何使用这个插件 我想使用servlet go连接elasticsearch并运行Servlets 使用servlet连接到Elasticsearch,servlets,elasticsearch,Servlets,elasticsearch,我不明白,如何使用这个插件 我想使用servlet go连接elasticsearch并运行 我的环境专用apache tomcat servlet,请帮助我,谢谢。我们的想法是通过添加以下依赖项来修改Mavenpom.xml(请确保根据您运行的ES版本使用): 这将实例化一个新的servlet,为http://server:8080/es/路径并将其代理到本地嵌入式Elasticsearch节点,这意味着您可以通过web应用程序查询ES。例如: curl -XGET http://server
我的环境专用apache tomcat servlet,请帮助我,谢谢。我们的想法是通过添加以下依赖项来修改Maven
pom.xml
(请确保根据您运行的ES版本使用):
这将实例化一个新的servlet,为http://server:8080/es/
路径并将其代理到本地嵌入式Elasticsearch节点,这意味着您可以通过web应用程序查询ES。例如:
curl -XGET http://server:8080/es/your_index/your_type/_search?q=*
上述查询相当于直接使用
curl -XGET http://localhost:9200/your_index/your_type/_search?q=*
主要区别在于,您还可以通过检索在servlet上下文中创建的Elasticsearch节点,从web应用程序中的任何位置(您可以访问ServletContext
)在内部查询ES,方法是:
Node node = getServletContext().getAttribute("elasticsearchNode")
最后,您可以将节点的Elasticsearch配置存储在
/WEB-INF/Elasticsearch.json
或/WEB-INF/Elasticsearch.yml
中。您有机会这样做吗?
curl -XGET http://localhost:9200/your_index/your_type/_search?q=*
Node node = getServletContext().getAttribute("elasticsearchNode")