弹性搜索和骆驼整合

时间:2014-04-21 20:20:58

标签: elasticsearch apache-camel

我正在尝试将camel与elasticsearch集成。 在applicationContext.xml中添加了以下内容

 <route id="timer-to-console">
        <from uri="timer://foo?fixedRate=true&amp;period=10s"/>
        <transform>
           <simple>Hello Web Application, how are you?</simple>
        </transform>
        <to uri="stream:out"/>
        <to uri="elasticsearch://local"/>
    </route>

然后当我跑

mvn jetty:run

我收到以下

veryCounter=0, firedTime=Mon Apr 21 13:14:43 PDT 2014}
BodyType            String
Body                Hello Web Application, how are you?
]

 Stacktrace
  ----------------------------------------------------------------------------------------      
 java.lang.IllegalArgumentException: operation is missing
at    org.apache.camel.component.elasticsearch.ElasticsearchProducer.process(ElasticsearchProducer.java:54)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)

我的弹性搜索在本地运行,我使用的是ES 1.1.1。

我需要为

指定什么
elasticsearch://clusterName[?options]

谢谢,

2 个答案:

答案 0 :(得分:1)

快速浏览Apache Camel Elasticsearch Component页面,他们会看到以下示例:

  

elasticsearch://本地操作= INDEX&安培; INDEXNAME = Twitter并安培; INDEXTYPE =鸣叫

这将INDEX(添加)到名为twitter的索引中,类型为tweet。您可以使用indexName和indexType所需的任何值。

更新:再次查看Elasticsearch Camel组件文档...我认为为了在弹性搜索连接中使用local作为服务器名称,您需要运行本地Elasticsearch实例,其clustername为local。默认情况下,Elasticsearch配置(elasticsearch.yml)设置为以elasticsearch

的聚类名称运行

答案 1 :(得分:0)

您必须使用elasticsearch.yml中指定的群集名称,即如果它显示为cluster.name: elasticsearch123,那么您必须按如下方式路由:

from("file:data_json?noop=true&moveFailed=data_json/.error") .convertBodyTo(byte[].class) .to("elasticsearch://elasticsearch123?operation=INDEX&indexName=myindexname&indexType=mytypename");

使用local根本不适合我。不幸的是,它甚至不会抛出任何使调试变得困难的错误。

另请注意转化.convertBodyTo(byte[].class) - 这也是必不可少的,否则Camel会将JSON文件转换为类Properties(它会查找从GenericFile到{{}的转换1}}它找到了Map的回退类型转换器。当然,您也可以转换为组件支持的其他类型。

还值得一提的是版本Properties的camel-elasticsearch组件依赖于2.14.1,考虑到Elasticsearch的移动速度有多快,这是一个很老的版本(当前版本为{{1}并且它经常喜欢破坏兼容性。也就是说,该组件似乎与Elasticsearch org.elasticsearch:elasticsearch:1.0.0一起使用。

更新:GitHub上的当前主分支已将Elasticsearch升级到版本1.4.4https://github.com/apache/camel/blob/2470023e25b8814279cbadb3ebc8002bed6d8fc8/parent/pom.xml#L144

参数/ clusterName 1.4.3实际上意味着它将从Elasticsearch的JavaDoc(NodeBuilder.local(boolean))中查找在同一JVM中启动的Elasticsearch实例:

  

本地节点是使用本地(JVM级别)发现的节点   运输。在同一个JVM(实际上是类加载器)中启动的其他(本地)节点将是   发现并与之沟通。将无法发现JVM外部的节点。