初步分析 Elasticsearch 文档

2023-04-06 09:37:03 浏览数 (1)

Query DSL

Elasticsearch提供基于JSON的完整查询DSL(Domain Specific Language)来定义查询。

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html

例如:

代码语言:javascript复制
GET /_search
{
  "query": { 
    "bool": { 
      "must": [
        { "match": { "title":   "Search"        }},
        { "match": { "content": "Elasticsearch" }}
      ],
      "filter": [ 
        { "term":  { "status": "published" }},
        { "range": { "publish_date": { "gte": "2015-01-01" }}}
      ]
    }
  }
}

REST API

https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html

  • Document APIs
  • Index APIs
  • SQL APIs

SQL

https://www.elastic.co/guide/en/elasticsearch/reference/current/xpack-sql.html

代码语言:javascript复制
POST _sql?format=txt
{
    "query": "SELECT title FROM article limit 10"
}

SQL翻译API

SQLQuery DSL

代码语言:javascript复制
POST /_sql/translate
{
  "query": "SELECT * FROM article ORDER BY id DESC",
  "fetch_size": 10
}

三个双引号的使用(使用 Kibana Console 才支持)

代码语言:javascript复制
POST /_sql/translate
{
  "query": """
  SELECT * FROM "index-*" ORDER BY id DESC
  """,
  "fetch_size": 10
}

SQL CLI

中文有乱码,待解决。。

代码语言:javascript复制
root@elasticsearch:/usr/share/elasticsearch# ./bin/elasticsearch-sql-cli

# root@elasticsearch:/usr/share/elasticsearch# ./bin/elasticsearch-sql-cli https://some.server:9200

# root@elasticsearch:/usr/share/elasticsearch# ./bin/elasticsearch-sql-cli https://sql_user:strongpassword@some.server:9200

sql> SELECT title FROM article limit 10;
                 title                 
---------------------------------------
vmware u5b89u88c5 android-x86    
Elastic Stack
logstash
yum logstash
Docker - Android
Docker for Android SDK
docker-compose RocketMQ           
vscode php         

sql> 

Command line tools

命令行工具

https://www.elastic.co/guide/en/elasticsearch/reference/current/commands.html

  • 重置密码

Snapshot and restore(快照和恢复)

elasticsearch 快照和恢复

https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-restore.html

php操作文档

https://www.elastic.co/guide/en/elasticsearch/client/php-api/8.7/operations.html

参考

https://www.elastic.co/guide/index.html

0 人点赞