3

I am working on elastic-search v1.1.1 I faced a problem with search queries .I want to know How solve below obstacle

Here is my mapping

{
  "token" : {
               "type" : "string"
            }
}

Data in indexed record is

 {
   token : "4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd"
 }

My search is

4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd

I want exact match of the record ,which query I need to use to get exact match of the record can it be done

  QueryBuilders.queryString() ?

I checked with queryString() ,then I finalized its not useful for exact match

Please suggest me

3
  • try token:"4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd" Commented Jul 11, 2014 at 13:46
  • queryString() returns either 4r5etgg or kogignjj or jdjuty687 or ofijfjfhf or kdjudyhd match. i want exact match like 4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd Commented Jul 11, 2014 at 13:50
  • Any reason why this got down voted (somebody down voted before)? It seems like they want to send people to paid forums. Commented Jul 11, 2014 at 21:24

2 Answers 2

4

You can put quotes around the string to do an exact match:

QueryBuilders.queryString("\"4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd\"");

If you don't want partial matches on the above string index an untokenized version of the value and search on that. In you mapping add:

"token": {
    "type": "multi_field",
    "fields": {
        "untouched":   { 
            "type": "string", 
            "index": "not_analyzed" 
        }
    }
}

Then search:

{
    "query": {
        "match": {
           "token.untouched": "4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd"
         }
     }
}
Sign up to request clarification or add additional context in comments.

1 Comment

QueryBuilders.queryString("\"4r5etgg\"") and QueryBuilders.queryString("\"kogignjj\"") and QueryBuilders.query("\"jdjuty687\"") and QueryBuilders.queryString("\"ofijfjfhf"") and QueryBuilders.queryString("\"kdjudyhd\"") are returning same record.I expecting exact match .
2

Change the mapping so ElasticSearch doesn't touch your data while indexing like so to:

{
  "token" : {
    "type" : "string",
    "index": "not_analyzed" 
  }
}

And then run a TermQuery from java like this

QueryBuilders.termQuery("token", "4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd");

That should give you your exact match.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.