How to write java code for elasticsearch DSL query

Shahin Alam

Lets take the following example,

    curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
    "query" : {
        "term" : { "user" : "kimchy" }
    }
  }

Which libraries can we use in order to get the response back from the end point with those body?

Please take note that , it is not likely that GET request will have body. I am aware of this.

dadoonet

With elasticsearch < 5.0, you can read the Java API guide.

SearchResponse response = client.prepareSearch("twitter")
    .setTypes("tweet")
    .setQuery(QueryBuilders.termQuery("user", "kimchy"))
    .get();

From 5.0 (and also for previous versions), you can start using the REST Java API documented here.

EDIT: the question was not precise enough. Adding this:

I built my own client at some point but switched to the Official REST one which is much more easier to use. You can see that here: https://github.com/dadoonet/fscrawler/blob/master/src/main/java/fr/pilato/elasticsearch/crawler/fs/client/ElasticsearchClient.java.

You can see my old home made REST client here https://github.com/dadoonet/fscrawler/blob/c9c00f7da6ecdcc3bfc99bcd530ceb653088f3a4/src/main/java/fr/pilato/elasticsearch/crawler/fs/client/ElasticsearchClient.java

But again, I'd recommend you to use the REST official client. Or be more specific about the issues you have with this.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to rewrite ElasticSearch DSL query with the Java API

From Dev

How to write elasticsearch query aggregation in java?

From Dev

How to write a conditional query with Elasticsearch?

From Dev

Elasticsearch DSL Query for Update

From Java

How to use ElasticSearch JSON DSL in Java?

From Dev

How to query two types with same field name ElasticSearch with Java code

From Dev

how to log or print python elasticsearch-dsl query that gets invoked

From Dev

how to find the nearest / closest number using Query DSL in elasticsearch

From Dev

Elasticsearch DSL query with specific Output

From Dev

Mix DSL and URI query in Elasticsearch

From Dev

Range or missing - ElasticSearch - Query DSL

From Dev

How to write elasticsearch multiple query condition?

From Dev

Elasticsearch java api: how to define fields as you would with _source:[] in dsl

From Dev

write mongoDB find query in java code

From Dev

How to write this JSON into Elasticsearch Java API?

From Dev

How to write Java code into JavaScript

From Dev

how to write the java code into matlab?

From Dev

Confusions about the Elasticsearch json dsl query structure

From Dev

Elasticsearch DSL query from an SQL statement

From Dev

elasticsearch-dsl-py query formation

From Dev

Django-Elasticsearch-DSL Nested Range Query

From Dev

Using Elasticsearch DSL Query with Hadoop Mapreduce

From Dev

Using elasticsearch dsl query with multiple indices

From Dev

Mapping logical queries to elasticsearch query DSL

From Dev

Query DSL elasticsearch doesn't work

From Dev

Exclude term in elasticsearch_dsl filter query

From Dev

Elasticsearch DSL query - Get all matching results

From Dev

ElasticSearch: How to write query where string field is either null or empty?

From Dev

How to write date range query in Nest ElasticSearch client?

Related Related

  1. 1

    How to rewrite ElasticSearch DSL query with the Java API

  2. 2

    How to write elasticsearch query aggregation in java?

  3. 3

    How to write a conditional query with Elasticsearch?

  4. 4

    Elasticsearch DSL Query for Update

  5. 5

    How to use ElasticSearch JSON DSL in Java?

  6. 6

    How to query two types with same field name ElasticSearch with Java code

  7. 7

    how to log or print python elasticsearch-dsl query that gets invoked

  8. 8

    how to find the nearest / closest number using Query DSL in elasticsearch

  9. 9

    Elasticsearch DSL query with specific Output

  10. 10

    Mix DSL and URI query in Elasticsearch

  11. 11

    Range or missing - ElasticSearch - Query DSL

  12. 12

    How to write elasticsearch multiple query condition?

  13. 13

    Elasticsearch java api: how to define fields as you would with _source:[] in dsl

  14. 14

    write mongoDB find query in java code

  15. 15

    How to write this JSON into Elasticsearch Java API?

  16. 16

    How to write Java code into JavaScript

  17. 17

    how to write the java code into matlab?

  18. 18

    Confusions about the Elasticsearch json dsl query structure

  19. 19

    Elasticsearch DSL query from an SQL statement

  20. 20

    elasticsearch-dsl-py query formation

  21. 21

    Django-Elasticsearch-DSL Nested Range Query

  22. 22

    Using Elasticsearch DSL Query with Hadoop Mapreduce

  23. 23

    Using elasticsearch dsl query with multiple indices

  24. 24

    Mapping logical queries to elasticsearch query DSL

  25. 25

    Query DSL elasticsearch doesn't work

  26. 26

    Exclude term in elasticsearch_dsl filter query

  27. 27

    Elasticsearch DSL query - Get all matching results

  28. 28

    ElasticSearch: How to write query where string field is either null or empty?

  29. 29

    How to write date range query in Nest ElasticSearch client?

HotTag

Archive