Query with match and wildcard

I have some tagged images in my Elasticsearch and want to query them with a wildcard and an exact match.

POST images/image
{
  "fileName": "1319410514097402934+test",
  "tags": ["someTag", "someOtherTag"]
}
POST images/_search
{
  "query": {
    "bool": {
      "must": { "wildcard": { "fileName": "*test" },
      "filter": { "match": { "tags": ["someTag"] } }
    }
  }
}

But I'm getting the following error:

{
  "type": "illegal_state_exception",
  "reason": "Can't get text on a START_ARRAY at 1:79"
}

How do I fix this?

Try this:

POST images/_search
{
  "query": {
    "bool": {
      "must": [{ "wildcard": { "fileName": "*test" }],
      "filter": [{ "match": { "tags": ["someTag"] } }]
    }
  }
}

BTW this is scary to run: { "wildcard": { "fileName": "*test" }. Unless you like slow queries, don't do that.

1 Like

Thanks, I will try this :slight_smile:

BTW this is scary to run: { "wildcard": { "fileName": "*test" } . Unless you like slow queries, don't do that.

What should I do instead?

Your query didn't work. :slightly_frowning_face:

I'm still getting the array error:

{
    "type": "illegal_state_exception",
    "reason": "Can't get text on a START_ARRAY at 1:82"
}

Sent this:

{
    "query": {
        "bool": {
            "must": [
                {
                    "wildcard": {
                        "fileName": "*test"
                    }
                }
            ],
            "filter": [
                {
                    "match": {
                        "tags": [
                            "no"
                        ]
                    }
                }
            ]
        }
    }
}

The match query is incorrect.

GET _search
{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "fileName": "*test"
          }
        }
      ],
      "filter": [
        {
          "match": {
            "tags": "no"
          }
        }
      ]
    }
  }
}

I see, so I "have to" use "tags": "no" for one value in the array and "tags": ["no", "people"] for multiple ones?

Multiple match queries I'd say.

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