0
我是新來的麋鹿, 我有elasticsearch的簡單的代碼在Java中是這樣的:fieldQuery(字符串,字符串)是未定義
Settings settings = Settings.settingsBuilder()
.put("cluster.name", "elasticsearch")
.put("client.transport.sniff", true).build();
TransportClient client = TransportClient.builder().settings(settings).build();
client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("1.2.3.4", 9200)));
SearchResponse response = client.prepareSearch("logstash-log*").setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(fieldQuery("host", "2.3.4.5"))
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();
SearchHit[] results = response.getHits().getHits();
for (SearchHit hit : results) {
System.out.println(hit.getId()); //prints out the id of the document
Map<String,Object> result = hit.getSource(); //the retrieved document
}
System.out.println("test");
所以,你可以給我建議,我一直在尋找解決方案 謝謝...
仍然不能使用termQuery,因爲我得到了錯誤信息「方法termQuery(String,String)未定義」 – stefansaye
您需要添加'import static org.elasticsearch.index.query.QueryBuilders.termQuery;' – Val
您是否已經能夠嘗試一下嗎? – Val