user3658423
user3658423

Reputation: 1944

elasticsearch wildcard index type

In elasticsearch, is it possible to define wildcard types (index)?

For example: I have an index named miner and have types P1, P2, N1, N2.

I want to search index: miner with all types starting with 'P'. I tried 'P*' and does not work. Is it possible?

client.search({
  index: 'miner',
  type: 'P*',

Thank you

Upvotes: 1

Views: 648

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52368

You need a prefix query for field _type. My example below demonstrates the prefix query together with whatever else you would like to search your index:

GET /miner/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "prefix": {
            "_type": {
              "value": "test"
            }
          }
        },
        {
          "match": {
            "name": "bob"
          }
        }
      ]
    }
  }
}

Upvotes: 1

Related Questions