Searching not analyzed term name and value in case insensitive manner

Hi @anjith.p,

a scripting solution is possible but this will be painfully slow compared to a native search.

Here is a working example (tested with Elasticsearch 2.3.3):

Enable file based scripting in config/elasticsearch.yml:

script.file: true

Add a file "match.groovy" in config/scripts/:

doc['name'].value.toLowerCase() == 'bob'

Note: You can use parameters in scripts (see docs) but this is a minimalistic example so I've hardcoded the value but I hope you get the idea.

Create an index:

PUT cases
{
   "mappings": {
      "people": {
         "properties": {
            "name": {
               "type": "string",
               "index": "not_analyzed"
            }
         }
      }
   }
}

Now add Bob:

POST /cases/people/1
{
    "name": "Bob"
}

And search via a script query:

GET /cases/people/_search
{
   "query": {
      "bool": {
         "must": [
            {
               "match_all": {}
            }
         ],
         "filter": {
            "script": {
               "script": {
                   "file": "match"
               }
            }
         }
      }
   }
}

You get:

{
   "took": 202,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "cases",
            "_type": "people",
            "_id": "1",
            "_score": 1,
            "_source": {
               "name": "Bob"
            }
         }
      ]
   }
}

Now the same with a term query:

GET /cases/people/_search
{
    "query": {
        "term": {
           "name": {
              "value": "Bob"
           }
        }
    }
}
{
   "took": 9,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.30685282,
      "hits": [
         {
            "_index": "cases",
            "_type": "people",
            "_id": "1",
            "_score": 0.30685282,
            "_source": {
               "name": "Bob"
            }
         }
      ]
   }
}

I had just one document stored and you already see the performance difference: 9 ms vs 202 ms. Please keep this in mind and test the performance early because it will be much slower with this approach.

Daniel