# Filtered alias with a \_default\_ mapping?

**URL:** <https://discuss.elastic.co/t/filtered-alias-with-a--default--mapping/20698>\
**Category:** Elasticsearch\
**Created:** [November 11, 2014, 10:06pm UTC](https://discuss.elastic.co/t/filtered-alias-with-a--default--mapping/20698 "2014-11-11T22:06:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Reed](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Dave\_Reed](https://discuss.elastic.co/u/Dave_Reed)\
**Post date:** [November 11, 2014, 10:06pm UTC](https://discuss.elastic.co/t/filtered-alias-with-a--default--mapping/20698/1 "2014-11-11T22:06:46Z")

</div>

I have an index that will end up containing a few hundred types. I'm  
dynamically creating these types based on some app logic. Each one can have  
a different mapping, but they have some similarities.

One of these similarities is that all the documents across all the types  
can be soft-deleted. Soft deleted documents are still indexed for some  
administration purposes, but I don't want them to appear in search results.  
So I tried creating a filtered alias.

First the mapping sets up the deleted field mapping, using _default_:

"mappings": {  
"_default_": {  
"properties": {  
"deleted": {  
"type": "boolean"  
}  
}  
}  
}

Then, I create the alias right after creating the index, like so:

POST /\_aliases  
{  
"actions": [  
{  
"add": {  
"index": "myindex\_v1",  
"alias": "myindex",  
"filter": { "term": { "deleted": false } }  
}  
}  
]  
}

But, when searching by this alias, no documents are ever matched. It's not  
a problem with the search, because changing it to use the actual index name  
works fine. I only get 0 results when using the index alias name. If I  
recreate the alias with a remove/add alias post after I've indexed  
documents into it, it starts working.

I suspected the _default_ mapping wasn't working with the alias filter. I  
though maybe it works if I recreate it after the documents are indexed  
because the real type mapping was dynamically generated by that time. So  
just to try it out, I hard coded my type mapping to a specific type,  
instead of _default_, and sure enough, that works.

So, am I correct that a _default_ mapping is not sufficient to make a  
filtered alias work? Is there a better way to achieve the requirement of  
always filtering out soft-deleted documents from search results without  
having to tag on filter criteria to every search?

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/aeb464cf-17a3-4e23-9539-c759e30c6b3e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/aeb464cf-17a3-4e23-9539-c759e30c6b3e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:50am UTC](https://discuss.elastic.co/t/filtered-alias-with-a--default--mapping/20698/2 "2017-07-06T00:50:41Z")

</div>

Closed on July 6, 2017, 12:50am UTC


