# Alias with query clause

**URL:** <https://discuss.elastic.co/t/alias-with-query-clause/130083>\
**Category:** Elasticsearch\
**Created:** [May 1, 2018, 2:22am UTC](https://discuss.elastic.co/t/alias-with-query-clause/130083 "2018-05-01T02:22:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattkallo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkallo/32/109746_2.png) [@mattkallo](https://discuss.elastic.co/u/mattkallo)\
**Post date:** [May 1, 2018, 2:22am UTC](https://discuss.elastic.co/t/alias-with-query-clause/130083/1 "2018-05-01T02:22:43Z")

</div>

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" }}
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [May 1, 2018, 3:05am UTC](https://discuss.elastic.co/t/alias-with-query-clause/130083/2 "2018-05-01T03:05:08Z")

</div>

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" }}
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 29, 2018, 3:05am UTC](https://discuss.elastic.co/t/alias-with-query-clause/130083/3 "2018-05-29T03:05:14Z")

</div>

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