初步分析 Elasticsearch 文档

编辑于 2023-04-04 23:59:25 阅读 1227

Query DSL

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

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

例如:

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

SQL

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

POST _sql?format=txt
{
    "query": "SELECT title FROM article limit 10"
}

SQL翻译API

SQLQuery DSL

POST /_sql/translate
{
  "query": "SELECT * FROM article ORDER BY id DESC",
  "fetch_size": 10
}

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

POST /_sql/translate
{
  "query": """
  SELECT * FROM "index-*" ORDER BY id DESC
  """,
  "fetch_size": 10
}

SQL CLI

中文有乱码,待解决。。

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

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验