I have the following documents inserted in an ElasticSearch domain.
{"depID:": "5656", "employeeID": "7777", "jobID": "2345"}
{"depID:": "6767", "employeeID": "9999", "jobID": "2345"}
{"depID:": "7676", "employeeID": "8888", "jobID": "2345"}
When I perform a SearchRequest on depID, I get 0 hits. But when I perform it on employeeIDs or jobIDs I'm getting the correct hits in response. I'm not sure what I'm doing wrong here. Below is how I'm creating these documents.
public IndexResponse indexDocumentRequest(final String indexName, final String jsonDocument) throws IOException {
IndexRequest indexRequest = new IndexRequest(indexName);
indexRequest.source(jsonDocument, XContentType.JSON);
return restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
}
IndexResponse indexResponse =
esDao.indexDocumentRequest("employees", "{\"depID:\": \"5656\", \"employeeID\": \"7777\", \"jobID\": \"2345\"}");
Below is the method in which I'm running the SearchRequests.
public SearchResponse searchDocumentRequest(final String indexName, final String jsonDocument) throws IOException {
QueryBuilder queryBuilder = QueryBuilders.wrapperQuery(jsonDocument);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(queryBuilder);
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices(indexName);
searchRequest.source(searchSourceBuilder);
return restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
}
Below is how I'm calling the above Search method.
SearchResponse searchResponse = esDao.searchDocumentRequest("employees",
"{\"bool\":{\"must\":[{\"match\":{\"depID\":\"5656\"}}]}}");
SearchResponse searchResponse = esDao.searchDocumentRequest("employees",
"{\"bool\":{\"must\":[{\"match\":{\"depID\":\"6767\"}}]}}");
None of the above calls return any hits! But the below calls on other fields return the correct hits.
SearchResponse searchResponse = esDao.searchDocumentRequest("employees",
"{\"bool\":{\"must\":[{\"match\":{\"employeeID\":\"7777\"}}]}}");
SearchResponse searchResponse = esDao.searchDocumentRequest("employees",
"{\"bool\":{\"must\":[{\"match\":{\"jobID\":\"2345\"}}]}}");
What am I doing wrong here? Why won't the depID searches not return any hits? Any advice would be much appreciated
UPDATE: The index mapping I have for the documents seem to be as follows.
{
"properties": {
"jobID": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"depID:": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"employeeID": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}