Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use queryString() in elasticsearch (java API)?

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

like image 983
Arepalli Praveenkumar Avatar asked Aug 12 '26 02:08

Arepalli Praveenkumar


1 Answers

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"
         }
     }
}
like image 69
Dan Tuffery Avatar answered Aug 14 '26 15:08

Dan Tuffery