javaelasticsearchakkaakka-streamalpakka

Using ElasticsearchSource to filter results in Elastic


Here I'm using this code to read data from an index where timestamp is >= 1656055230028:

        Source<ReadResult<Map<String, Object>>, NotUsed> source =
                ElasticsearchSource.create(
                        constructElasticsearchParams("data", "_doc", ApiVersion.V7),
" \"range\": {" +
        "      \"timestamp\": {" +
        "        \"gte\": 1656055230028" +
        "          , \"boost\": 2.0" +
        "      }" +
        "    }",sourceSettings);

this returns 0 results, however using the query on Elastic dev tools :

GET /data/_search
{
  "query": {
    "range": {
      "timestamp": {
        "gte": 1656055230028,
        "boost": 2.0
      }
    }
  }
}

returns data.

Is the format of the request used in the Java code above correct?


Solution

  • This query works as expected :

    "{ \"bool\": {  \"must\" : [{\"range\" : {"+
                    "\"timestamp\" : { "+
                    "\"gte\" : 1656055230028
                    +" }} }]}} "