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
provider
field is of object or nested type, while in your query you are just mentioningCoursera
but it should be matched against thename
subfield ofprovider
field and based on object or nested data type, you need to modify your query.You are using the
term query
which is not analyzed and used for keyword ie extact match while if yourname
field is defined astext
it would be lowercased at index time andCoursera
with captialC
won’t match, you need to use thematch
query on text fields.