Die Dev Tools Console in OpenSearch Dashboards ist ein leistungsfähiges Werkzeug für Entwickler, mit dem Sie direkt mit OpenSearch interagieren, Abfragen testen und die Antworten analysieren können.
Die Dev Tools Console besteht aus zwei Hauptbereichen:
# Index erstellen
PUT /mein-index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
}
}
# Dokument indexieren
POST /mein-index/_doc
{
"field1": "value1",
"field2": "value2"
}
# Suche ausführen
GET /mein-index/_search
{
"query": {
"match": {
"field1": "value1"
}
}
}
# Mehrere Anfragen in einem Block
POST _bulk
{"index": {"_index": "test", "_id": "1"}}
{"field": "value1"}
{"index": {"_index": "test", "_id": "2"}}
{"field": "value2"}
# Nächste Anfrage
GET test/_search
{
"query": {
"match_all": {}
}
}
# Variable definieren
POST _scripts/my-template
{
"script": {
"lang": "mustache",
"source": {
"query": {
"match": {
"{{field}}": "{{value}}"
}
}
}
}
}
# Template verwenden
GET test/_search/template
{
"id": "my-template",
"params": {
"field": "name",
"value": "john"
}
}
GET /mein-index/_search
{
"profile": true,
"query": {
"match": {
"field1": "test"
}
}
}
GET /mein-index/_explain/1
{
"query": {
"match": {
"field1": "test"
}
}
}
# Text-Analyse durchführen
GET _analyze
{
"analyzer": "standard",
"text": "This is a test"
}
# Index-spezifische Analyse
GET mein-index/_analyze
{
"field": "field1",
"text": "This is a test"
}
GET /_nodes/hot_threads
# Index mit Mapping erstellen
PUT /products
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"price": {
"type": "float"
},
"category": {
"type": "keyword"
}
}
}
}
# Alias hinzufügen
POST /_aliases
{
"actions": [
{
"add": {
"index": "products",
"alias": "current_products"
}
}
]
}
# Aggregierte Suche
GET /products/_search
{
"size": 0,
"query": {
"range": {
"price": {
"gte": 100
}
}
},
"aggs": {
"categories": {
"terms": {
"field": "category",
"size": 10
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
# Reindex mit Transformation
POST _reindex
{
"source": {
"index": "old_products"
},
"dest": {
"index": "new_products"
},
"script": {
"source": """
ctx._source.price *= 1.1;
ctx._source.last_updated = System.currentTimeMillis();
"""
}
}
Die wichtigsten Tastenkombinationen:
Ctrl + Enter: Ausführen der aktuellen AnfrageCtrl + I: Auto-IndentCtrl + /: Kommentar ein/ausCtrl + Space: Auto-Complete# Effiziente Query-Struktur
GET /products/_search
{
"_source": ["name", "price"],
"query": {
"bool": {
"filter": [
{
"term": {
"category": "electronics"
}
},
{
"range": {
"price": {
"gte": 100,
"lte": 500
}
}
}
]
}
}
}
# Cluster-Status überprüfen
GET /_cluster/health
# Index-Statistiken
GET /products/_stats
# Shard-Allokation
GET /_cat/shards?v
# Fehlersuche bei fehlgeschlagenen Anfragen
GET /_cat/indices?v&health=red
# Recovery-Status
GET /_recovery?active_only=true
# Pending Tasks
GET /_cluster/pending_tasks