elasticsearchelasticsearch-6

Elastic search - search api query


I have an index named "bank"(added from this link), with sample data like:

{
      "account_number" : 25,
      "balance" : 40540,
      "firstname" : "Virginia",
      "lastname" : "Ayala",
      "age" : 39,
      "gender" : "F",
      "address" : "171 Putnam Avenue",
      "employer" : "Filodyne",
      "email" : "virginiaayala@filodyne.com",
      "city" : "Nicholson",
      "state" : "PA"
}

When I do request body search it works for some keys and for some it doesn't. For e.g

GET /bank/_search
{
    "query" : {
        "term" : {"age" : 39}
    }
}

Above request works, while the below one doesn't return any response(0 response)

GET /bank/_search
{
    "query" : {
        "term" : {"firstname" : "Virginia"}
    }
}

What is reason for above? What should be done to fetch the result based on any keys


Solution

  • For string fields, it will pass the string through the standard analyzer which lowercases it. For instance, the standard analyzer would turn the string “Quick Brown Fox!” into the terms [quick, brown, fox]. This is why your query doesn't work.

    You can solve this using :