High Rest Client | Search for any value from list

I have a simple index contains filename and status and I want to get all documents contains any filename from a given list.

Below is a document sample:

{
    "_index" : "filestracking",
    "_type" : "_doc",
    "_id" : "File_2020_05_22_001.csv",
    "_score" : 1.0,
    "_source" : {
       "fileName" : "File_2020_05_22_001.csv",
       "status" : "EXPECTED"
    }
}

I wrote a simple query to receive all documents that their fileName match a value from a list:

SearchRequest searchRequest = new SearchRequest(trackingIndex);
QueryBuilder query = QueryBuilders.termsQuery("fileName", fileList);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(query);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = getSearchResponseWithAttempts(searchRequest);
searchResponse.getHits().getHits();

but I find nothing (fileList is a List).

Can you help me please, how to find all documents match any value of a given list (fileList) ?

Thank you!

EDIT
_id and fileName contains same values. searching for _id return results (fileName is of text type in the mapping).
I don't know why _id works but if you know I'll be glad to know too :slight_smile:

Change it to keyword or use the keyword analyzer on this field.

If you are using the default mapping, you can may be run the query against fileName.keyword.