0

i am new to elk, I have an simple code of elasticsearch in Java like this :

 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");

So, can you give me suggestion, I've looking for the solution Thanks...

stefansaye
  • 135
  • 1
  • 3
  • 16

1 Answers1

1

You should use termQuery("host", "2.3.4.5") instead.

fieldQuery() was an old query available in ES 0.90, which has been deprecated and removed.

Val
  • 207,596
  • 13
  • 358
  • 360
  • still cannot use termQuery because i got the error msg "The method termQuery(String, String) is undefined" – stefansaye May 12 '16 at 07:28
  • You need to add `import static org.elasticsearch.index.query.QueryBuilders.termQuery;` – Val May 12 '16 at 07:29
  • Have you been able to try this out? – Val May 13 '16 at 04:07
  • Can you explain what you mean by "get all field value"? – Val May 13 '16 at 06:00
  • Any chance with this? – Val May 17 '16 at 12:37
  • hi Val, return results is get _id field, but how can i get all field that host is 1.2.3.4 – stefansaye May 23 '16 at 03:42
  • This question was about `fieldQuery` vs `termQuery ` and you said it worked after adding the `import` statement. If you have a different issue now, you should ask a new question so that we don't cram too much into this thread. – Val May 23 '16 at 04:11
  • hi Val,the issuse have crated http://stackoverflow.com/questions/37384276/how-to-using-regexp-in-elasticsearch , can you give me suggestion, I've looking for the solution Thanks... – stefansaye May 23 '16 at 08:25
  • None of the three answers satisfy you? – Val May 23 '16 at 08:28