Elasticsearch : Filter does not work with wildcard query

169 Views Asked by At

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?

Edit

here is what a typical response looks like with both fields included

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

        "Col2": [
                "asd"
              ]
        }
      }

for query

POST indexName/test/_search
    {
      "fields" : ["Col1","Col2"],
      "query":{
                            "wildcard": {

                                "Col1": {

                                      "value": "*zxc*"
                                   }
                                }

                }
    }

similar results for the other one

0

There are 0 best solutions below