ElasticSearch - search with Java Set Collection


(Nikita Krasnov) #1

Hello to everyone.
I have such code:

     @PostMapping("/findLogsByValues")
        @Transactional
        public ResponseEntity findLogsByValues(@RequestBody ElasticSearchLogRequest esLogRequest) {
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    BoolQueryBuilder bqb = QueryBuilders.boolQuery();   
 ...    
if (esLogRequest.getLevels() != null) {
                Iterator<String> iterator = esLogRequest.getLevels().iterator();
                while (iterator.hasNext()) {
                    bqb.filter(QueryBuilders.termQuery("level", iterator.next()));
                }
            }
...
    }

My json:
{
"levels": ["DEBUG", "INFO"]
}

So, I want to find all logs which have field name "level" with value "INFO" or "DEBUG".
esLogRequest.getLevels() respond with Set collection (Set levels).
Due to my code (which I placed behind), I get response with null values:

{
    "code": 200,
    "error": "",
    "message": "",
    "data": {
        "scrollId": null,
        "totalShards": 36,
        "successfulShards": 36,
        "skippedShards": 0,
        "shardFailures": [],
        "clusters": {
            "total": 0,
            "successful": 0,
            "skipped": 0,
            "fragment": true
        },
        "timedOut": false,
        "profileResults": {},
        "numReducePhases": 1,
        "terminatedEarly": null,
        "aggregations": null,
        "suggest": null,
        "took": {
            "hours": 0,
            "minutes": 0,
            "seconds": 0,
            "millis": 17,
            "nanos": 17000000,
            "days": 0,
            "millisFrac": 17,
            "micros": 17000,
            "secondsFrac": 0.017,
            "minutesFrac": 0.00028333333333333335,
            "microsFrac": 17000,
            "daysFrac": 1.9675925925925927e-7,
            "hoursFrac": 0.000004722222222222222,
            "stringRep": "17ms"
        },
        "hits": {
            "hits": [],
            "totalHits": 0,
            "maxScore": "NaN",
            "fragment": true
        },
        "failedShards": 0,
        "fragment": false
    }
}

But such values exists in ES. What I'm doing wrong?


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.