[id='queries_by_keys_{context}']
= Queries by keys

You can define the key of a cache entry as `Indexed` type to index the key fields as well the value fields allowing the keys to be used in Ickle queries.

To define an `Indexed` key, specify the fully qualified name of the ProtocolBuffer message type to use as the key type in the `keyEntity` attribute of the `@Indexed` annotation.

[NOTE]
====
This feature is available only with indexed remote queries.
====

.Specify the `keyEntity` of an indexed entity
[source,java]
----
include::code_examples/Structure.java[]
----

.Define the key entity and its indexed fields
[source,java]
----
include::code_examples/StructureKey.java[]
----

== Key property name

By default, the key fields will be targeted using the property named `key`.

.Use key properties in the Ickle queries
[source,slq]
----
select s.key.column from model.Structure s where s.key.zone = 'z7'
----

If the value already has a property named `key`, the definition of the key entity could create a naming conflict
with the properties.
For this reason, and also in general,
it is possible to change the name to assign as a prefix for the property keys changing the attribute `keyPropertyName`
of the `@Indexed` annotation.

== Key include depth

An entity key can have embedded entities. You can limit the depth for the embedded entity fields that are indexed by changing the attribute `keyIncludeDepth`, which defaults to `3`.

