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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/aeb464cf-17a3-4e23-9539-c759e30c6b3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to