How to search case sensitive in elasticsearch without mapping

I am creating an elasticsearch app where i need to case sensitive search without use of mapping. So please suggest me how to do this.

Without mapping, by default your fields will be a keyword type, meaning not analyzed by Elasticsearch.
In that case you will make a term search, on the exact match.

https://www.elastic.co/guide/en/elasticsearch/reference/master/keyword.html

Is term query case sensitive? Actually when i search word "Dog" with term query it shows the result for dog and Dog both where i want result only for Dog(exact match) without mapping.How can i solve this problem please suggest me.

But you did not change the mapping, did you?

If you can't make it work, provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Without mapping, you should use :

{
  "query": {
    "term": {
      "your_field.keyword": {
        "value": "Dog"
      }
    }
  }
}

If this doesn't work,
Indeed could you provide us, more details : mapping + query?

`I am working on an elasticsearch app i want the case sensitive search but i am facing the problem.
I am using the process just given below -

Step -1 index creating and insert records in to it.

PUT index

PUT index/doc/1
{
"animal": "Quick fox or dog "
}
PUT index/doc/2
{
"animal": "quick fox or dog "
}

Step 2- Now searching

GET index/_search
{
"query": {
"term": {
"animal": "Quick"
}
}
}

Then result show none
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}

But when i use the query with word "quick" given below -
GET index/_search
{
"query": {
"term": {
"animal": "quick"
}
}
}
it shows the result like -
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.2876821,
"hits": [
{
"_index": "index",
"_type": "doc",
"_id": "2",
"_score": 0.2876821,
"_source": {
"animal": "quick fox or dog "
}
},
{
"_index": "index",
"_type": "doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"animal": "Quick fox or dog "
}
}
]
}
}

so i am unable to find exact mach of searched word "Quick".

Please suggest me so that i can solve this problem.

i am using the query -

GET index/_search
{
"query": {
"term": {
"animal.keyword":{"value":"Quick"}
}
}
}

even then no result found.

Can you provide your mapping for the index please?

I am not using mapping as i discussed above. I want exact search without use of mapping if i use mapping its create a problem of re-indexing to remove or change mapping .

If mapping changes need to be made on your current data then yes, a re-index would be needed. Would it be possible to show your mapping to help troubleshoot? Thanks!

All fields are mapped in Elasticsearch, so you can not run without mappings. What happens when you do not explicitly specify mappings is that Elasticsearch applies default mappings dynamically, which may or may not suit your needs.

When i use the below given mapping then result found

PUT /index
{
"settings": {
"analysis": {
"analyzer": {
"mymapping": {
"type": "custom",
"tokenizer": "standard"
}
}
}
},
"mappings": {
"type": {
"properties": {
"animal": {
"type": "string",
"analyzer": "mymapping"
}
}
}
}
}

But i don't want to use of this mapping to avoid the re-indexing problem.

thanks for this

You have to use some mapping, and if you want to change it you will need to reindex.

Thanks for your suggestion.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.