Lets say I have document in the Elastic Search which does containt field “provider” in the _source.
I have tryied many queries but none of them seem to return the document with searched value.
Doc:
"_source" : {
"jobs" : [ ],
"provider" : {
"id" : "1",
"name" : "Coursera"
},
"sckLevels" : [ ],
"scks" : [ ],
"trArea" : [ ],
"trElems" : [ ],
"training" : {
"description" : "Cyber sec desc",
"id" : "0",
"img" : "img link",
"link" : "https://google.com",
"name" : "Cyber sec",
"trainingProvID" : "1"
}
And my code for the query is:
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.termQuery("provider", "Coursera"));
searchRequest.source(sourceBuilder);
this.multiRequest.add(searchRequest);
My response is blank.
Thank you.
Advertisement
Answer
There is definitely few issues with your Elasticsearch query
Seems
providerfield is of object or nested type, while in your query you are just mentioningCourserabut it should be matched against thenamesubfield ofproviderfield and based on object or nested data type, you need to modify your query.You are using the
term querywhich is not analyzed and used for keyword ie extact match while if yournamefield is defined astextit would be lowercased at index time andCourserawith captialCwon’t match, you need to use thematchquery on text fields.