Alias with query clause

Does alias allow queries inside like below? Or it allows only filters? I am able to create the alias with below, but the match clause doesn't seem to be working. Any alternatives to this? Thanks

PUT /sports/_alias/baseball
{ 
  "query": { 
    "bool": { 
      "must": [
        { "match": { "content": "baseball" }}  
      ],
      "filter": [ 
        { "term":  { "processed": "true" }}
      ]
    }
  }
}

You're almost there, you just need to use the filter keyword instead of query

PUT /sports/_alias/baseball
{ 
  "filter": {                <--- change this
    "bool": { 
      "must": [
        { "match": { "content": "baseball" }}  
      ],
      "filter": [ 
        { "term":  { "processed": "true" }}
      ]
    }
  }
}

However, since this is really a filter (i.e. there is no scoring involved, the goal is just to tell if a document should come up in the alias or not), you can move the match from the must to the filter section, like this:

PUT /sports/_alias/baseball
{ 
  "filter": {                <--- change this
    "bool": { 
      "filter": [ 
        { "match": { "content": "baseball" }},            <--- and this
        { "term":  { "processed": "true" }}
      ]
    }
  }
}
1 Like

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