ElasticSearch 2.1.1 (4) - API Convention

The elasticsearch REST APIs are exposed using JSON over HTTP.

Mutiple Indices

Simple notation

test1,test2,test3

_all

Wildcards

test*

Add & Remove

+test*,-test3

API support

  • ignore_unavailable

      true or false
  • allow_no_indices

      true or false
  • expand_wildcards

      open or close
    
      none or all

Data match support in index names

A date math index name takes the following form:

<static_name{date_math_expr{date_format|time_zone}}>
  • static_name

    is the static text part of the name

  • date_math_expr

    is a dynamic date math expression that computes the date dynamically

  • date_format

    is the optional format in which the computed date should be rendered. Defaults to YYYY.MM.dd.

  • time_zone

    is the optional time zone . Defaults to utc.

      curl -XGET 'localhost:9200/<logstash-{now%2Fd-2d}>/_search' {
    "query" : {
    ...
    }
    }

    The / used for date rounding must be url encoded as %2F in any url.

Expression:

Given the current time is 22rd March 2024 noon utc.

    ----------------------------------------------------------------------
Expression | Resolves to
----------------------------------------------------------------------
<logstash-{now/d}> | logstash-2024.03.22
----------------------------------------------------------------------
<logstash-{now/M}> | logstash-2024.03.01
----------------------------------------------------------------------
<logstash-{now/M{YYYY.MM}}> | logstash-2024.03
----------------------------------------------------------------------
<logstash-{now/M-1M{YYYY.MM}}> | logstash-2024.02
----------------------------------------------------------------------
<logstash-{now/d{YYYY.MM.dd|+12:00}} | logstash-2024.03.23
----------------------------------------------------------------------

Static {}:

<elastic\\{ON\\}-{now/M}> resolves to elastic{ON}-2024.03.01

Searches the Logstash indices for the past three days:

curl -XGET 'localhost:9200/<logstash-{now%2Fd-2d}>,<logstash-{now%2Fd-1d}>,<logstash-{now%2Fd}>/_search' {
"query" : {
...
}
}

Common options

Pretty Results

?pretty=true

?format=yaml

Human readable outputedit

?human=false	("exists_time_in_millis": 3600000 or "size_in_bytes": 1024)

?human=true 	("exists_time": "1h" or "size": "1kb")

Date Math

  • range queries

      gt and lt
  • daterange aggregations

      from and to
  • expression

      now or ||

    followed:

    • +1h - add one hour

    • -1h - substract one hour

    • /d - round down to the nearest day

    supported time units:

    y (year), M (month), w (week), d (day), h (hour), m (minute), and s (second)

  • examples

      -----------------------------------------------------------------------------------------
    now+1h | The current time plus one hour, with ms resolution.
    -----------------------------------------------------------------------------------------
    now+1h+1m | The current time plus one hour plus one minute, with ms resolution.
    -----------------------------------------------------------------------------------------
    now+1h/d | The current time plus one hour, rounded down to the nearest day.
    -----------------------------------------------------------------------------------------
    2015-01-01||+1M/d | 2015-01-01 plus one month, rounded down to the nearest day.
    -----------------------------------------------------------------------------------------

Response Filtering

  • filter_path

      curl -XGET 'localhost:9200/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score'
    {
    "took" : 3,
    "hits" : {
    "hits" : [
    {
    "_id" : "3640",
    "_score" : 1.0
    },
    {
    "_id" : "3642",
    "_score" : 1.0
    }
    ]
    }
    }
  • * wildcard

      curl -XGET 'localhost:9200/_nodes/stats?filter_path=nodes.*.ho*'
    {
    "nodes" : {
    "lvJHed8uQQu4brS-SXKsNA" : {
    "host" : "portable"
    }
    }
    }
  • ** wildcard

      curl 'localhost:9200/_segments?pretty&filter_path=indices.**.version'
    {
    "indices" : {
    "movies" : {
    "shards" : {
    "0" : [ {
    "segments" : {
    "_0" : {
    "version" : "5.2.0"
    }
    }
    } ],
    "2" : [ {
    "segments" : {
    "_0" : {
    "version" : "5.2.0"
    }
    }
    } ]
    }
    },
    "books" : {
    "shards" : {
    "0" : [ {
    "segments" : {
    "_0" : {
    "version" : "5.2.0"
    }
    }
    } ]
    }
    }
    }
    }
  • _source

      curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title'
    {
    "hits" : {
    "hits" : [ {
    "_source":{"title":"Book #2"}
    }, {
    "_source":{"title":"Book #1"}
    }, {
    "_source":{"title":"Book #3"}
    } ]
    }
    }

Flat Setting

  • true

      {
    "persistent" : { },
    "transient" : {
    "discovery.zen.minimum_master_nodes" : "1"
    }
    }
  • false (default)

      {
    "persistent" : { },
    "transient" : {
    "discovery" : {
    "zen" : {
    "minimum_master_nodes" : "1"
    }
    }
    }
    }

Parameters

Rest parameters (when using HTTP, map to HTTP URL parameters) follow the convention of using underscore casing.

Boolean Values

  • "false"

      false, 0, no and off
  • "true"

      others

Number Values

Native JSON number types

	string

Time units

    ------------------------------
y | Year
------------------------------
M | Month
------------------------------
w | Week
------------------------------
d | Day
------------------------------
h | Hour
------------------------------
m | Minute
------------------------------
s | Second
------------------------------
ms | Milli-second
------------------------------

Distance Units

    -----------------------------------------
Mile | mi or miles
-----------------------------------------
Yard | yd or yards
-----------------------------------------
Feet | ft or feet
-----------------------------------------
Inch | in or inch
-----------------------------------------
Kilometer | km or kilometers
-----------------------------------------
Meter | m or meters
-----------------------------------------
Centimeter | cm or centimeters
-----------------------------------------
Millimeter | mm or millimeters
-----------------------------------------
Nautical mile | NM, nmi or nauticalmiles
-----------------------------------------

The precision parameter in the Geohash Cell Query accepts distances with the above units, but if no unit is specified, then the precision is interpreted as the length of the geohash.

Fuzziness

  • Numberic, date and IPv4 fields

    Range Query

      -fuzziness <= field value <= +fuzziness

    fuzziness

    • numberic

        2 or 2.0
    • date

        a long as milliseconds
    • string

        1h
    • ip

        a long or IPv4 address (will be converted into a long)
  • String fields

    Levenshtein Edit Distance

    • 0, 1, 2

    • AUTO

      For lengths:

      0..2 - must match exactly

      3..5 - one edit allowed

      >5 - two edits allowed

Result Casing

  • underscore casing (default)

  • camelCase

Note, this does not apply to the source document indexed.

Request body in query string

For libraries that don’t accept a request body for non-POST requests, you can pass the request body as the source query string parameter instead.

URL-based access control

config.yml file:

rest.action.multi.allow_explicit_index: false

Reference

https://www.elastic.co/guide/en/elasticsearch/reference/current/api-conventions.html

ElasticSearch 2 (4) - API Convention的更多相关文章

  1. elasticsearch中的API

    elasticsearch中的API es中的API按照大类分为下面几种: 文档API: 提供对文档的增删改查操作 搜索API: 提供对文档进行某个字段的查询 索引API: 提供对索引进行操作 查看A ...

  2. Elasticsearch利用cat api快速查看集群状态、内存、磁盘使用情况

    使用场景 当Elasticsearch集群中有节点挂掉,我们可以去查看集群的日志信息查找错误,不过在查找错误日志之前,我们可以通过elasticsearch的cat api简单判断下各个节点的状态,包 ...

  3. Elasticsearch for python API模块化封装

    Elasticsearch for python API模块化封装 模块的具体功能 检测Elasticsearch节点是否畅通 查询Elasticsearch节点健康状态 查询包含的关键字的日志(展示 ...

  4. Springboot整合elasticSearch的官方API实例

    前言:在上一篇博客中,我介绍了从零开始安装ElasticSearch,es是可以理解为一个操作数据的中间件,可以把它作为数据的存储仓库来对待,它具备强大的吞吐能力和计算能力,其基于Lucene服务器开 ...

  5. Elasticsearch中JAVA API的使用

    1.Elasticsearch中Java API的简介 Elasticsearch 的Java API 提供了非常便捷的方法来索引和查询数据等. 通过添加jar包,不需要编写HTTP层的代码就可以开始 ...

  6. elasticsearch【cat API,系统数据】指令汇总

    本博文讲述的ES获取系统数据的API是基于Elasticsearch 2.4.1版本的. 0. overview a. 下面将要介绍的所有的指令,都支持一个查询参数v(verbose),用来显示详细的 ...

  7. Elasticsearch使用REST API实现全文检索

    通过rest api添加检索数据,阅读官方文档可以发现,elasticsearch支持动态映射,但是其中有不少问题,且听慢慢详解. 本文主要讲述三点内容: 1 Elasticsearch常用的rest ...

  8. 【重新分配分片】Elasticsearch通过reroute api重新分配分片

    elasticsearch可以通过reroute api来手动进行索引分片的分配. 不过要想完全手动,必须先把cluster.routing.allocation.disable_allocation ...

  9. elasticsearch 6.0java api的使用

    elasticsearch 6.0 中java api的使用 1:使用java api创建elasticsearch客户端 package com.search.elasticsearch; impo ...

随机推荐

  1. NOIP模拟赛-2018.10.22

    模拟赛 今天第一节课是历史,当然是不可能上的,一来到机房发现今天高二考试... 老师说以后可能还要给高一考...那还不如现在跟着做好了,毕竟在学长学姐中垫底显得没那么丢人 这套题风格挺奇怪的...为什 ...

  2. BZOJ4919:[Lydsy1706月赛]大根堆(set启发式合并)

    Description 给定一棵n个节点的有根树,编号依次为1到n,其中1号点为根节点.每个点有一个权值v_i. 你需要将这棵树转化成一个大根堆.确切地说,你需要选择尽可能多的节点,满足大根堆的性质: ...

  3. Android友盟推送

    当前版本号:v3.0.5 1.下载SDK解压并导入(import module,compile project(':PushSDK')),里面有demo,用demo的包名去官网添加一个应用,然后替换d ...

  4. uname -a输出内容分析

    uname -a输出内容分析 uname --help 将每个参数都单独执行一次,得到: ------------------------------------------------------- ...

  5. 计算机视觉-sift(2)代码理解

    之前结合不同人的资料理解了sift的原理,这里通过opencv中的代码来加深对sift的实现的理解. 使得能够从原理性理解到源码级的理解.不过该博文还是大量基于<赵春江, opencv2.4.9 ...

  6. ORA-02291: 违反完整约束条件 - 未找到父项关键字

    由于大意,在设置数据库表时将外键字段的类型与外键表的主键字段类型不一致,造成此错误. 我的情况是: 1.将一个为number(10)的外键设置成了number(19) 2.将外键字段对应的主键表设置成 ...

  7. 树形DP 复习

    树形DP 树形DP:建立在树上的动态规划 一般有两种传递方式:根→叶或叶→根 前者出现在换根DP中,一般操作是求出某一个点的最优解,再通过这一个点推知其他点的最优解. 后者是树形DP的常见形式,一般树 ...

  8. [HAOI2008]排名系统 & [Zjoi2006]GameZ游戏排名系统 BZOJ1862&BZOJ1056

    分析: 平衡树裸题,(学完LCT感觉自己不会普通的Splay了...),维护每个节点的权值大小顺序,和时间戳顺序,之后map维护一下是否存在过,(懒得写字符串hash了). 附上代码: #includ ...

  9. 2017-2018-2 《网络对抗技术》 20155302 第二周 Exp1 PC平台逆向破解(5)M

    2017-2018-2 <网络对抗技术> 20155302 第二周 Exp1 PC平台逆向破解(5)M 1-实践目标 1.1-实践介绍 本次实践的对象是一个名为pwn1的linux可执行文 ...

  10. 20155334 《网络攻防》Exp4 恶意代码分析

    <网络攻防>Exp4 恶意代码分析 一.实验问题回答 如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有哪些,用什么方法来监 ...