94.7. 검색 예
특정 필드 및 값에 대한 검색은 Operation 'Search'를 사용합니다. 쿼리 JSON 문자열 또는 맵으로 전달
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);