94.7. 搜索示例
根据特定字段和值搜索,使用 Operation 'Search'。传递查询 JSON String 或 Map
from("direct:search") .to("elasticsearch-rest://elasticsearch?operation=Search&indexName=twitter&indexType=tweet");
<route> <from uri="direct:search" /> <to uri="elasticsearch-rest://elasticsearch?operation=Search&indexName=twitter&indexType=tweet"/> </route>
String query = "{\"query\":{\"match\":{\"content\":\"new release of ApacheCamel\"}}}"; SearchHits response = template.requestBody("direct:search", query, SearchHits.class);
使用 Map 搜索特定字段。
Map<String, Object> actualQuery = new HashMap<>(); actualQuery.put("content", "new release of ApacheCamel"); Map<String, Object> match = new HashMap<>(); match.put("match", actualQuery); Map<String, Object> query = new HashMap<>(); query.put("query", match); SearchHits response = template.requestBody("direct:search", query, SearchHits.class);