_type field filter vs. field filter performance

I am trying to figure out how to setup my index mapping.

I currently have all my documents in one index and under one type. However, there is one field (~2000+ unique terms) in my document that could be used as a _type mapping. I am wondering if there is any difference in query performance if that field is a type mapping vs. as a single field. AFAIK, all a type mapping does is insert a _type field for that document.


Here is how I have it now:

index/general

{
f_id: 1,
name: "foo"
},
{
f_id: 2,
name: "bar"
}


Here is a potential example with using the field as a type mapping:

index/1
{
name: "foo"
}

index/2
{
name: "bar"
}

I'd use the field over the type mapping. Just make sure it is a number or a keyword. That gives you the flexibility to make it multi-valued if you find you have to do that one day. Honestly, one type per index is way, way simpler if you can get away with it.

Ok, so ease of use aside, is there any performance benefit to filtering on a type when querying?

In 99% of the cases filtering on type is the same speed as filtering one term. If you happen to want to allow any one of many terms then filtering on a terms query is actually going to be faster.

1 Like

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