Combine wildcard and exact match


(Anand V) #1

I am new to querying in elasticsearch. I am trying to match a field with wildcard and a few more fields with exact match. I am not able to form a proper query. Can someone help me?


(David Pilato) #2

Could you 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.


(Anand V) #3

The following gives me appropriate search where my index is tracking-number-details:

http://localhost:9200/tracking-number-details/_search?q=*w333ny8*&size=1000

But I need to search a few more fields to match. I tried the following:

{
	"size" : 1000,
	"bool": {
	      "should": [
	     	{ "match": {"number":"84W333" }},
	        {"match": {"client_id":"21" }}]
	      },
	   "query" :{
		
			"wildcard" : {
            				"tracking_number": "*w333ny82441914*"
	    				}
	    
}
}

but it gives error:
{"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [bool].","line":3,"col":10}],"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [bool].","line":3,"col":10},"status":400}

I tried even this:

{
	
	"query" :{
	      "multi_match": {
            "query": "1Z84W333NW* 84W333 21",
       "type":       "cross_fields",
       "analyzer":   "standard",
       "fields":     [  "tracking_number^3","number","client_id" ]
   }
}
}

But it gives matches of 1Z84W333NW* which are partial to this text. I need help to figure better to write.


(David Pilato) #4

2 comments:

  • Your text is not correctly formatted as per instructions I linked to
  • I can not copy and paste what you posted to test it in Kibana, as per instructions.

Please follow the instructions if you need help.


(Anand V) #5

I have edited as you asked. If I still need me to do something more, please suggest


(David Pilato) #6

I can not copy and paste what you posted to test it in Kibana.

I don't have any data to play with.

To explain more. This is useless:

{
	"size" : 1000,
	"bool": {
	      "should": [
	     	{ "match": {"number":"84W333" }},
	        {"match": {"client_id":"21" }}]
	      },
	   "query" :{
		
			"wildcard" : {
            				"tracking_number": "*w333ny82441914*"
	    				}
	    
}
}

This is useful:

DELETE index
PUT index/_doc/1
{
  "foo": "bar"
}
GET index/_search
{
  "query": {
    "match": {
      "foo": "bar"
    }
  }
}

See the difference?


(system) #7

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