Elasticsearch: Match query returns wrong results (Java API)

Jan

I have the following problem: When I execute this command

curl -XGET "localhost:9200/customer/external/_search?pretty" -d @json.txt

Where json.txt looks like this:

{ "query":{ "match":{ "_id":"1" } } }

I get the following output (I shortened it):

{
   "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "customer",
      "_type" : "external",
      "_id" : "1",
      "_score" : 1.0,
      "_source":{
        "name":"Jan",
        "age":99,
        "address":{
            "city":"KKKKKKK",
            "zip":"xxxx"
        }
      }
    } ]
}

Now I'm trying to do the same using the Java API but I just cannot manage to get it done (I tried like 8 different approches). I get always 0 hits. In the code I now set the source file as a string directly as a source but as you can see I also tried using the XContentBuilder and WrapperQueryBuilder versions but nothing worked. Here's my code:

public void processQuery(String filePath, String index, String... types) {
    String source = convertFileToString(filePath);

    //XContentBuilder query = null;
    //try {
    //  JSONObject json = new JSONObject(source.trim());
    //  query = convertJsonToXContentBuilder(json);
    //} catch (...) {...}

    //WrapperQueryBuilder query = QueryBuilders.wrapperQuery(source);

    SearchResponse response = client.prepareSearch(index)
            .setSource(source)
    //      .setQuery(query)
            .setTypes(types)
            .get();
}

As a response I dont get any hits at all:

{
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

I hope anyone has an idea about this cause I'm already sick of trying to find a solution :/

Best regardes, Jan

Jan

Sry for the new "answer" but I cannot edit my question. So I figured smth out but I don't know how to progress now. When I run in debug mode it works fine (I'm using it in a JUnit test). So I thought maybe I'm closing the connection too early so I added a Thread.sleep(5000) but it still fails. It only works in debug mode :/ If its important I'm using the TransportClient.

It's a bit awkward but I hope someone might know the cause...

Cheers, Jan

Edit:

the problem is solved: Since I was using this in unit tests and I emptied and reloaded the content of the DB everytime, the content wasn't ready yet when the request was executed. I'm waiting now for the status to be green and then start the tests.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Elasticsearch query yeilds no results

From Dev

Filtered Query in Elasticsearch Java API

From Dev

elasticsearch | template query | java API

From Dev

Query returns wrong result

From Dev

Java API to match multiple fields in elasticsearch

From Dev

Why is ElasticSearch match query returning all results?

From Dev

ElasticSearch - Match (email value) returns wrong registers

From Dev

ElasticSearch NEST term query returns no results

From Dev

Add _timestamp to Elasticsearch results using Java API

From Dev

Are ElasticSearch query results cached?

From Dev

Elasticsearch returns unmatched results

From Dev

Elasticsearch match all query using Java API

From Dev

Mysql query returns no results

From Dev

PHP ajax API some times returns wrong results

From Dev

The order by clause returns wrong results in sub query

From Dev

java elasticsearch query without java API

From Dev

ElasticSearch NEST term query returns no results

From Dev

Query returns unwanted results

From Dev

Add _timestamp to Elasticsearch results using Java API

From Dev

SQL QUERY- multiple COUNT returns wrong (same) results

From Dev

Deleting data results related to a query using Java API Elasticsearch

From Dev

elasticsearch match query used against a field array returns bad results

From Dev

Elasticsearch "get by index" returns the document, while "match_all" returns no results

From Dev

multi_match query returning no results elasticsearch

From Dev

Junit test on DAO layer returns wrong results for postgresql exists() query

From Dev

Elastic Search match query returns incorrect results and score

From Dev

Google Analytics Query Explorer doesn't match api results

From Dev

Codeigniter returns wrong "pagination" results

From Dev

SQLite Database query returns wrong results

Related Related

  1. 1

    Elasticsearch query yeilds no results

  2. 2

    Filtered Query in Elasticsearch Java API

  3. 3

    elasticsearch | template query | java API

  4. 4

    Query returns wrong result

  5. 5

    Java API to match multiple fields in elasticsearch

  6. 6

    Why is ElasticSearch match query returning all results?

  7. 7

    ElasticSearch - Match (email value) returns wrong registers

  8. 8

    ElasticSearch NEST term query returns no results

  9. 9

    Add _timestamp to Elasticsearch results using Java API

  10. 10

    Are ElasticSearch query results cached?

  11. 11

    Elasticsearch returns unmatched results

  12. 12

    Elasticsearch match all query using Java API

  13. 13

    Mysql query returns no results

  14. 14

    PHP ajax API some times returns wrong results

  15. 15

    The order by clause returns wrong results in sub query

  16. 16

    java elasticsearch query without java API

  17. 17

    ElasticSearch NEST term query returns no results

  18. 18

    Query returns unwanted results

  19. 19

    Add _timestamp to Elasticsearch results using Java API

  20. 20

    SQL QUERY- multiple COUNT returns wrong (same) results

  21. 21

    Deleting data results related to a query using Java API Elasticsearch

  22. 22

    elasticsearch match query used against a field array returns bad results

  23. 23

    Elasticsearch "get by index" returns the document, while "match_all" returns no results

  24. 24

    multi_match query returning no results elasticsearch

  25. 25

    Junit test on DAO layer returns wrong results for postgresql exists() query

  26. 26

    Elastic Search match query returns incorrect results and score

  27. 27

    Google Analytics Query Explorer doesn't match api results

  28. 28

    Codeigniter returns wrong "pagination" results

  29. 29

    SQLite Database query returns wrong results

HotTag

Archive