Elasticsearch : Filter does not work with wildcard query


(Abhijit) #1

Here is my query

POST indexName/test/_search
{
  "fields" : ["Col1"],
  "query":{
	    				"filtered":{
	    				  
	    				"query":{
	    				  
	    				
	    				"wildcard": {
	    				  
	    					"Col1": {
	    					  
	    				          "value": "*zxc*"
	    				       }
	    				    }
	    				  
	    				  },
	    				"filter":
	            {
	  	          "term": { 
	  	            
	  	            "Col2": "val" 
	  	            
	  	          }
	            }
	    			}
	    				    
	    	}
}

so i want to do a wildcard on Col1 for the value *zxc* and i want only those values where Col2 is val this returns 0 hits. is there anything wrong with my syntax?

The wildcard query works independently if i remove the filter.

Edit

this works

POST indexName/test/_search
{
  "fields" : ["Col1"],
  "query":{
	    				"filtered":{
	    				  
	    				
	    				"filter":
	            {
	  	          "term": { 
	  	            
	  	            "Col2": "val" 
	  	            
	  	          }
	            }
	    			}
	    				    
	    	}
}

sample document returned

{
        "_index": "indexName",
        "_type": "test",
        "_id": "oainfubgvwurebetrnjt",
        "_score": 1,
        "fields": {
          "Col1": [
            "uyiwebvybg iuowenbgubnrwev  uirbgvuire3bv  vuirbg"
          ]
        }
      }

and so does this

POST indexName/test/_search
{
  "fields" : ["Col1"],
  "query":{
	    				"wildcard": {
	    				  
	    					"Col1": {
	    					  
	    				          "value": "*zxc*"
	    				       }
	    				    }
	    				    
	    	}
}

sample document returned

{
        "_index": "indexName",
        "_type": "test",
        "_id": "aofnhuiwegbnweu",
        "_score": 1,
        "fields": {
          "Col1": [
            "idasihid huwbgbuiwb iuohfuweb zxc oifjhwgbu"
          ]
        }
      }

so both of these queries work independently. How do i combine them?


(system) #2