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

I am working on elastic search v1.1.1 I ran into a problem with search queries. I want to know how to solve the obstacle below.

Here is my mapping

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

Data in Indexed Record

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

My search

4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd

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

  QueryBuilders.queryString() ?

I checked with queryString (), then I finalized it is not useful for an exact match

Please offer me

+3
source share
2 answers

You can put quotes around the string for exact matching:

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

, . :

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

:

{
    "query": {
        "match": {
           "token.untouched": "4r5etgg-kogignjj-jdjuty687-ofijfjfhf-kdjudyhd"
         }
     }
}
+4

, ElasticSearch :

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

TermQuery java,

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

.

+2

Source: https://habr.com/ru/post/1548735/


All Articles