0

I am querying ElasticSearch by using the following query and it is giving me results as per the query along with some other irrelevant data.

GET items/_search
{
  "query" :{
      "match": {"code": "*7000-8002-W*"}
  }
}

But if I query like this, I am getting the proper results:

GET items/_search
{
  "query" :{
      "match": {"code": "*S6617523*"}
  }
}

Why is the first query returns some other irrelevant data?

Srikanth Jeeva
  • 3,005
  • 4
  • 38
  • 58
Karthikeyan
  • 1,927
  • 6
  • 44
  • 109

1 Answers1

1

This behaviour is due to the way ES analyzes the string. In this case you need to apply wildcard query on raw field of code like

{ 
"query": { 
 "wildcard": { 
  "code.keyword": { 
  "value": "*7000-6000*" 
    } 
   } 
  } 
 }

Java API orresponding to this will be

QueryBuilders.wildcardQuery("code.keyword","*7000-6000*");

Hope this Helps!!

Richa
  • 7,419
  • 6
  • 25
  • 34