elasticsearch之所以功能比較強大,更多的是因爲其插件機制比較靈活,可以直接不需要改動源碼的情況下,被es的節點掃描加載。本篇文章就簡單的講一下如何進行調試插件,其實無論是river、analysis或者是其他的plugin,都是差不多的寫法,所以我們用其中一個river的插件來演示下如何進行調試。
首先,在github上git clone對應的elasticsearch的源碼,然後在intellij中將其import進來作爲project。
然後,在github上git clone elasticsearch-rabbitmq-river的源碼,然後在intellij中作爲elasticsearch項目的一個module進行import。
效果如圖,
接下來進行運行,這步是最重要的,也是如何讓plugin可以在elasticsearch加載的關鍵。
1、點擊run菜單選擇-》configure
2、新建一個application,Main class 選擇 org.elasticsearch.bootstrap.Bootstrap
3、Vm options 中填 -Des.foreground=true 保證可以讓es在前臺運行,並輸出日誌
4、最重要的,將Use classpath of module選擇爲插件的項目,即elasticsearch-river-rabbitmq
最後、Debug as 就OK了。