searchApiKeys #
Searches API keys for the currently logged user.
Kuzzle uses the ElasticSearch Query DSL syntax.
This method also supports the Koncorde Filters DSL to match documents by passing the lang
argument with the value koncorde
.
Koncorde filters will be translated into an Elasticsearch query.
Koncorde bool
operator and regexp
clauses are not supported for search queries.
An empty or null query will match all documents in the collection.
:::: tabs ::: tab Java
Arguments #
public CompletableFuture<SearchResult> searchApiKeys(
Map<String, Object> query) throws NotConnectedException, InternalException
public CompletableFuture<SearchResult> searchApiKeys(
Map<String, Object> query,
Integer from) throws NotConnectedException, InternalException
public CompletableFuture<SearchResult> searchApiKeys(
Map<String, Object> query
Integer from
Integer size) throws NotConnectedException, InternalException
public CompletableFuture<SearchResult> searchApiKeys(
Map<String, Object> query
Integer from
Integer size,
Lang lang) throws NotConnectedException, InternalException
Property | Type | Description |
---|---|---|
query | Map<String, Object> | Search query |
from | Integer ( 0 ) | (optional) Offset of the first document to fetch |
size | Integer | (optional) Maximum number of documents to retrieve per page |
lang | Lang | Specify the query language to use. By default, it's elasticsearch but koncorde can also be used. Available since 1.1.0 |
query #
The search query to apply to API keys content, using the ElasticSearch Query DSL syntax.
If left empty, the result will return all available API keys for the currently logged user.
Return #
Returns a SearchResult object.
Usage #
With the ElasticSearch Query DSL syntax.
Map<String, Object> description = new HashMap<>();
description.put("description", "LoRa permanent API Key");
Map<String, Object> query = new HashMap<>();
query.put("controller", "security");
query.put("action", "createApiKey");
query.put("userId", "jared.doe");
query.put("refresh", "wait_for");
query.put("_id", "lora-key");
query.put("body", description);
kuzzle.query(query).get();
description.put("description", "Sigfox API key");
query.put("_id", "sigfox-key");
query.put("body", description);
kuzzle.query(query).get();
description.put("description", "LoRa 6 month API key");
query.put("_id", "lora-temp-key");
query.put("body", description);
query.put("expiresIn", 36000);
kuzzle.query(query).get();
Map<String, Object> credentials = new HashMap<>();
credentials.put("username", "jared.doe");
credentials.put("password", "password");
kuzzle.getAuthController().login("local", credentials).get();
Map<String, Object> match = new HashMap<>();
match.put("description", "LoRa");
Map<String, Object> squery = new HashMap<>();
squery.put("match", match);
SearchResult results = kuzzle
.getAuthController()
.searchApiKeys(squery).get();
String output = String.format("Found %d API keys matching 'LoRa'", results.total);
System.out.println(output);
/*
{
"total"=2,
"hits"=[
{
"_id"="znEwbG8BJASM_0-bWU-q",
"_source"={
"description"="LoRa permanent API key",
"userId"="jared.doe",
"expiresAt"=-1,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl"=-1
}
},
{
"_id"="zXEwbG8BJASM_0-bWU-q",
"_source"={
"description"="LoRa 6 month API key",
"userId"="jared.doe",
"expiresAt"=31557600000,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl"=360000
}
}
]
}
*/
With the Koncorde Filters DSL syntax.
Map<String, Object> description = new HashMap<>();
description.put("description", "LoRa permanent API Key");
Map<String, Object> query = new HashMap<>();
query.put("controller", "security");
query.put("action", "createApiKey");
query.put("userId", "jared.doe");
query.put("refresh", "wait_for");
query.put("_id", "lora-key");
query.put("body", description);
kuzzle.query(query).get();
description.put("description", "Sigfox API key");
query.put("_id", "sigfox-key");
query.put("body", description);
kuzzle.query(query).get();
description.put("description", "LoRa 6 month API key");
query.put("_id", "lora-temp-key");
query.put("body", description);
query.put("expiresIn", 36000);
kuzzle.query(query).get();
Map<String, Object> credentials = new HashMap<>();
credentials.put("username", "jared.doe");
credentials.put("password", "password");
kuzzle.getAuthController().login("local", credentials).get();
Map<String, Object> equals = new HashMap<>();
equals.put("ttl", "36000");
Map<String, Object> squery = new HashMap<>();
squery.put("equals", equals);
SearchResult results = kuzzle
.getAuthController()
.searchApiKeys(squery, Lang.KONCORDE).get();
String output = String.format("Found %d API key", results.total);
System.out.println(output);
/*
{
"total"=2,
"hits"=[
{
"_id"="zXEwbG8BJASM_0-bWU-q",
"_source"={
"description"="LoRa 6 month API key",
"userId"="jared.doe",
"expiresAt"=31557600000,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl"=360000
}
}
]
}
*/
::: ::: tab Kotlin
Arguments #
fun searchApiKeys(
query: Map<String, Any?>,
from: Int = 0,
size: Int? = null,
lang: Lang = Lang.ELASTICSEARCH): CompletableFuture<SearchResult>
Property | Type | Description |
---|---|---|
query | Map<String, Any?> | Search query |
from | Int ( 0 ) | (optional) Offset of the first document to fetch |
size | Int | (optional) Maximum number of documents to retrieve per page |
lang | Lang | Specify the query language to use. By default, it's elasticsearch but koncorde can also be used. Available since 1.1.0 |
query #
The search query to apply to API keys content, using the ElasticSearch Query DSL syntax.
If left empty, the result will return all available API keys of the currently logged user.
Return #
Returns a SearchResult object.
Usage #
With the ElasticSearch Query DSL syntax.
val description: HashMap<String?, Any?> = HashMap<String?, Any?>().apply {
put("description", "LoRa permanent API Key")
}
val query: HashMap<String?, Any?> = HashMap<String?, Any?>().apply {
put("controller", "security")
put("action", "createApiKey")
put("userId", "jared.doe")
put("refresh", "wait_for")
put("_id", "lora-key")
put("body", description)
}
kuzzle.query(query).get()
description.put("description", "Sigfox API key")
query.put("_id", "sigfox-key")
query.put("body", description);
kuzzle.query(query).get()
description.put("description", "LoRa 6 month API key")
query.put("_id", "lora-temp-key")
query.put("body", description);
query.put("expiresIn", 36000);
kuzzle.query(query).get()
kuzzle.authController.login("local", HashMap<String, Any?>().apply {
put("username", "jared.doe")
put("password", "password")
}).get()
val match: HashMap<String, Any?> =
HashMap<String, Any?>().apply {
put("description", "LoRa")
}
val squery: HashMap<String, Any?> =
HashMap<String, Any?>().apply {
put("match", match)
}
val results = kuzzle
.authController
.searchApiKeys(squery).get();
print("Found ${results.total} API keys matching 'LoRa'");
/*
{
"total"=2,
"hits"=[
{
"_id"="znEwbG8BJASM_0-bWU-q",
"_source"={
"description"="LoRa permanent API key",
"userId"="jared.doe",
"expiresAt"=-1,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl"=-1
}
},
{
"_id"="zXEwbG8BJASM_0-bWU-q",
"_source"={
"description"="LoRa 6 month API key",
"userId"="jared.doe",
"expiresAt"=31557600000,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl"=360000
}
}
]
}
*/
With the Koncorde Filters DSL syntax.
val description: HashMap<String?, Any?> = HashMap<String?, Any?>().apply {
put("description", "LoRa permanent API Key")
}
val query: HashMap<String?, Any?> = HashMap<String?, Any?>().apply {
put("controller", "security")
put("action", "createApiKey")
put("userId", "jared.doe")
put("refresh", "wait_for")
put("_id", "lora-key")
put("body", description)
}
kuzzle.query(query).get()
description.put("description", "Sigfox API key")
query.put("_id", "sigfox-key")
query.put("body", description);
kuzzle.query(query).get()
description.put("description", "LoRa 6 month API key")
query.put("_id", "lora-temp-key")
query.put("body", description);
query.put("expiresIn", 36000);
kuzzle.query(query).get()
kuzzle.authController.login("local", HashMap<String, Any?>().apply {
put("username", "jared.doe")
put("password", "password")
}).get()
val equals: HashMap<String, Any?> =
HashMap<String, Any?>().apply {
put("ttl", "36000")
}
val squery: HashMap<String, Any?> =
HashMap<String, Any?>().apply {
put("equals", equals)
}
val results = kuzzle
.authController
.searchApiKeys(squery, lang = Lang.KONCORDE).get();
print("Found ${results.total} API key");
/*
{
"total"=2,
"hits"=[
{
"_id"="znEwbG8BJASM_0-bWU-q",
"_source"={
"description"="LoRa permanent API key",
"userId"="jared.doe",
"expiresAt"=-1,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl"=-1
}
},
{
"_id"="zXEwbG8BJASM_0-bWU-q",
"_source"={
"description"="LoRa 6 month API key",
"userId"="jared.doe",
"expiresAt"=31557600000,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl"=360000
}
}
]
}
*/
::: ::::