.keyword in query dsl

Dear ES staff

I am developing a plugin to connect to a local Elasticsearch cluster. I have to programmatically construct ES queries with to Query DSL and have problems with the keyword an text data type. I have done some tests with a small dataset. This is the mapping of the dataset:
{
"test3" : {
"mappings" : {
"_doc" : {
"properties" : {
"key1" : {
"type" : "text"
},
"key2" : {
"type" : "keyword"
},
"key3" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}

The question is: for which fields do I have to use the '.keyword' after the field?

In my tests, I noticed that for key3 (default datatype text and keyword) I have to use it for aggregations but cannot use it for filters. All good. So I implemented it this way.

When I try it on a different dataset also having a field with type: text and keyword. I don't get any results back. When I try it with the '.keyword' behind the field, I get the correct results. Could you explain me what the reason is for this different behaviour?

It's really up to you. Adding a fields mapping will configure the multi-fields feature which allows indexing the same value from a field with different mappings. Please, review the referred documentation for more information.

I am not sure I follow this completely. You should be able to use filters both in text and keyword datatypes.

I don't know the query that you are using, so it's difficult to provide more information. But it's important to understand that querying a field of type text is completely different from querying a field of type keyword. The first will be full-text search while the latter will be exact match. Review documentations for text and keyword for more information on the differences.