ElasticSearch Search for Field Values does not return

Tags: , ,

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.


"_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"));

My response is blank.

Thank you.


There is definitely few issues with your Elasticsearch query

  1. Seems provider field is of object or nested type, while in your query you are just mentioning Coursera but it should be matched against the name subfield of provider field and based on object or nested data type, you need to modify your query.

  2. You are using the term query which is not analyzed and used for keyword ie extact match while if your name field is defined as text it would be lowercased at index time and Coursera with captial C won’t match, you need to use the match query on text fields.

Source: stackoverflow