Elastic Search API Index。简单的介绍了使用Elastic Search 如何建立索引。

ElasticSearch-API-Index

索引创建API允许初始化一个索引。ElasticSearch对多重索引提供了支持,包括跨多个索引执行操作。每个索引在创建时可以让一个特定的设置项与其关联。

最简单的方式创建索引

curl -XPUT ‘http://localhost:9200/twitter/'

在创建索引的时候指定分片和副本数量,参数格式采用YAML格式

curl -XPUT ‘http://localhost:9200/twitter/‘ -d ‘

index:

number_of_shards:3

number_of_replicas:2



在创建索引的时候指定分片和副本数量参数,参数格式采用JSON格式

curl -XPUT ‘http://localhost:9200/twitter/‘ -d ‘{

“settings”:{

“index”:{

“number_of_shards”:3,

“number_of_replicas”:2

}

}

}’

或者简化为

curl -XPUT ‘http://localhost:9200/twitter’ -d ‘{

“settings”:{

“number_of_shards”:3,

“number_of_replicas”:2

}

}’

  • 请注意,你不需要在settings项中显示的指定index。

索引创建API可以接受一个或者一组映射选项

curl -XPOST localhost:9200/test -d ‘{

“settings”:{

“number_of_shards”:1

},

“mappings”:{

“type1”:{

“_source”:{“enabled”:false},

“preperties”:{

“field1”:{“type”:”string”,

”index”:”not_analyzed”

}

}

}

}

}’

REST风格的插入方式。

curl -XPOST http://localhost:9200/索引名称/索引类型/id -d JSON格式的参数

比如插入”twitter”的索引,并且索引类型为tweet

curl -XPUT ‘http://localhost:9200/twitter/tweet/1’ -d ‘{

“user”:”kimchy”,

“post_date”:”2012-12-12”,

“message”:”trying out ElasticSearch!”

}’

添加成功后,其会返回操作状态,索引、类型、id等信息如上例中返回信息

{

"ok" : true,

"_index" : "twitter",

"_type" : "tweet",

"_id" : "1"

}

每一个被索引的文档都会有一个版本号,被关联的版本号会作为index API的请求的响应信息一部分返回回来。因此,我们可以在对索引操作的时候,指定特定的版本号,操作对应版本的文档。例如

curl -XPUT ‘localhost:9200/twitter/tweet/1?version=2’ -d ‘{

“message”:”elasticsearch now has versioning support,double cool!”

}’

*注意 1.版本控制完全是实时的,不会影响接近实时方面的查询操作。如果版本已经被提供了,那么操作执行检查所有的版本。 2.默认情况下,版本从1开始,自增因子为1。

op_type。索引操作也接受参数op_type,用来强制创建索引的操作。如果索引尚未建立的时候,可以接受这样的行为,但是当文档的缩影已经存在的时候,该操作会将失败。 下面是一个op_type参数的例子

curl -XPUT ‘http://localhost:9200/twitter/tweet/1?op_type=create’ -d ‘{

“user”:”kimchy”,

“post_date”:”2014-12-05T14:12:12”,

“message”:”trying out Elastic Searche”

}’

另外的一种create方式

curl -XPUT ‘http://localhost:9200/twitter/tweet/1/_create’ -d ‘{

“user”:”kimchy”,

“post_date”:”2009-11-11T14:12:12”,

“message”:”hello,world”

}’

自动生成Id.在创建一个Index的操作中,如果没有指定id,系统将会自动地为其生成一个id.

curl -XPOST ‘http://localhost:9200/twitter/tweet/‘ -d ‘{

“user”:”kimchy”,

“post_date”:”2013-11-12T12:12:12”,

“message”:”Hello,world”

}’

操作响应的结果如下

{

“ok”:true,

“_index”:”twitter”,

“_type”:”tweet”,

“_id”:”6a8ca01c-7896-48e9-81cc-9f70661fcb32”

}

路由(Routing)。默认情况下,分片或路由是通过计算文档的hash值来控制的,为了更明确的控制值,送入路由器使用hash函数计算hash值的操作可以通过routing参数来控制。

curl -XPOST ‘http://localhost:9200/twitter/tweet?routing=kimchy’ -d ‘{

“user”:”kimchy”,

“post_date”:”2014-12-12T12:12:12”

}’

TTL。一个文档建立索引的时候,能够为其指定ttl。

curl -XPUT 'http://localhost:9200/twitter/tweet/1?ttl=86400000' -d '{

"user": "kimchy",

"message": "Trying out elasticsearch, so far so good?"

}'

curl -XPUT 'http://localhost:9200/twitter/tweet/1?ttl=1d' -d '{

"user": "kimchy",

"message": "Trying out elasticsearch, so far so good?"

}'

curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{

"_ttl": "1d",

"user": "kimchy",

"message": "Trying out elasticsearch, so far so good?"

}'

elasticsearch curl operation的更多相关文章

  1. Elasticsearch CURL命令

    1.查看集群状态 curl '10.18.37.223:9200/_cat/health?v'绿色表示一切正常, 黄色表示所有的数据可用但是部分副本还没有分配,红色表示部分数据因为某些原因不可用 2. ...

  2. elasticSearch curl 语法总结

    #创建索引a.put创建curl -XPUT http://localhost:9200/shb01/student/1-d'{"name":"jack",&q ...

  3. 利用kibana学习 elasticsearch restful api (DSL)

    利用kibana学习 elasticsearch restful api (DSL) 1.了解elasticsearch基本概念Index: databaseType: tableDocument: ...

  4. 以bank account 数据为例,认识elasticsearch query 和 filter

    Elasticsearch 查询语言(Query DSL)认识(一) 一.基本认识 查询子句的行为取决于 query context filter context 也就是执行的是查询(query)还是 ...

  5. 分布式搜索引擎Elasticsearch的简单使用

    官方网址:https://www.elastic.co/products/elasticsearch/ 一.特性 1.支持中文分词 2.支持多种数据源的全文检索引擎 3.分布式 4.基于lucene的 ...

  6. ubuntu安装配置elasticSearch(vagrant)

    安装jdk sudo apt-get install python-software-properties sudo add-apt-repository ppa:webupd8team/java s ...

  7. ELK——安装 logstash 2.2.0、elasticsearch 2.2.0 和 Kibana 3.0

    本文内容 Elasticsearch logstash Kibana 参考资料 本文介绍安装 logstash 2.2.0 和 elasticsearch 2.2.0,操作系统环境版本是 CentOS ...

  8. elasticsearch 安装

    ### USAGE ### ### ./ElasticSearch.sh 1.5.0 will install Elasticsearch 1.5.0 ### ./ElasticSearch.sh 1 ...

  9. ELK 之一:ElasticSearch 基础和集群搭建

    一:需求及基础: 场景: 1.开发人员不能登录线上服务器查看详细日志 2.各个系统都有日志,日志数据分散难以查找 3.日志数据量大,查询速度慢,或者数据不够实时 4.一个调用会涉及到多个系统,难以在这 ...

随机推荐

  1. Linux下部署FTP服务器

    Linux下部署FTP服务器 下载安装包 在这里介绍的是离线部署FTP,首先下载对应的rpm包,下载链接为: 下载vsftpd服务 下载FTP客户端 安装ftp服务器 关闭防火墙 service ip ...

  2. OpenStack 通用设计思路 - 每天5分钟玩转 OpenStack(25)

    API 前端服务 每个 OpenStack 组件可能包含若干子服务,其中必定有一个 API 服务负责接收客户请求. 以 Nova 为例,nova-api 作为 Nova 组件对外的唯一窗口,向客户暴露 ...

  3. vmstat命令

    vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深 ...

  4. php应用jquery做ajax操作

    以下是全部代码: <html> <head> <title>jQuery Ajax 实例演示</title> </head> <scr ...

  5. Ubuntu搭建Note.Js 平台

    1. 安装nodeJs和npm apt-get install nodejsapt-get install npm 2 .node有一个模块叫n,是专门用来管理node.js的版本的.首先安装n模块: ...

  6. 关于nfs共享目录的使用技巧

    nfs客户端的使用 1.查看nfs服务器信息挂载信息 1)在客户端,要查看nfs服务器上有哪些共享目录 # showmount -e nfs服务器ip 在客户端,要查看nfs服务器上有哪些客户端的目录 ...

  7. 当我学完Python时我学了些什么

    本文是本人学完Python后的一遍回顾,加深理解而已,Python大神请过~ 学习Python的这几天来,觉得Python还是比较简单,容易上手的,就基本语法而言,但是有些高级特性掌握起来还是有些难度 ...

  8. 用MonoDevelop开发Linux游戏

    鉴于微软将放弃XNA,MonoGame将是喜欢XNA的朋友们的新选择,他是XNA游戏引擎的开源实现,而且是跨平台的,这意味着你可以用他开发OS.android.windows以及linux应用程序,多 ...

  9. BZOJ 2330: [SCOI2011]糖果 [差分约束系统] 【学习笔记】

    2330: [SCOI2011]糖果 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 5395  Solved: 1750[Submit][Status ...

  10. 洛谷P1782 旅行商的背包[多重背包]

    题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能 ...