Problem:
Show how to:
- Return yml instead of JSON in response.
- Format JSON to look nice.
- Do not include source in search result.
- Select fields that needs to be returned.
Solution Summary:
We can use various parameters to controll the query results.
-
Return yml instead of JSON in response.
- We can use format=yaml
-
Format JSON to look nice.
- We can use pretty. Makes more sense when working from clients other than Kibana (e.g. terminal in Mac).
-
Do not include source in search result.
- We can set _source to false.
- Select fields that needs to be returned.
Prerequisites:
Solution Steps:
Case 1 - Returning YAML instead of JSON
GET /accounts/_search?format=yaml
{
"query": { "match_all": {} }
}
Case 2 - Formatting results using pretty
GET /accounts/_search?pretty
{
"query": { "match_all": {} }
}
Case 3 - Do not include any soure fields in result
GET /accounts/_search?pretty
{
"query": { "match_all": {} },
"_source": false
}
Case 4 - Selecting fields that needs to be returned
GET /accounts/_search?pretty
{
"query": { "match_all": {} },
"_source": ["account_number", "age"]
}
Case 5 - Using wildcard, includes and excludes for source filtering
GET /department/_search?pretty
{
"query": { "match_all": {} },
"_source": {
"includes": "employees.*",
"excludes": "employees.age"
}
}
Recent comments