elasticSearch笔记

useradd/passwd
test/wangchao
elasticUser/elasticUser
插件安装
安装head,http://localhost:9200/_plugin/head/访问
1:bin/plugin -install mobz/elasticsearch-head
2:mkdir \plugins\head_site
解压zip放置site
安装ik
mvn package
target\releases\解压复制 /plugs/ik

chmod -R 777 ./elasticsearch-2.4.4

ps -ef | grep elastic
./elasticsearch -d
kill -9 19678
10.249.12.81

curl -XDELETE ‘10.249.12.81:9200/customer’
curl -XPUT ‘10.249.12.81:9200/customer’

192.168.3.14
curl ‘192.168.3.14:9200/_cat/indices?v’
覆盖集群节点名:./elasticsearch –cluster.name my_cluster_name –node.name my_node_name
查看状态:curl ‘10.249.12.81:9200/_cat/health?v’
获取节点列表:curl ‘localhost:9200/_cat/nodes?v’
列出所有索引:curl ‘localhost:9200/_cat/indices?v’

创建索引:curl -XPUT ‘localhost:9200/customer?pretty’
添加document
curl -XPUT ‘localhost:9200/customer/external/1?pretty’ -d ’
{
“name”: “John Doe”
}’
检索index:curl -XGET ‘localhost:9200/customer/external/1?pretty’
删除
curl -XDELETE ‘localhost:9200/customer?pretty’
curl ‘localhost:9200/_cat/indices?v’

总结
curl -XPUT ‘localhost:9200/customer’
curl -XPUT ‘localhost:9200/customer/external/1’ -d ’
{
“name”: “John Doe”
}’

curl 'localhost:9200/customer/external/1'
curl -XDELETE 'localhost:9200/customer'

curl -X :///

新增文档时
id指向一个文档
id不变,文档覆盖
不指定id,id随机生成

修改id为1文档
curl -XPOST ‘localhost:9200/customer/external/1/_update?pretty’ -d ’
{
“doc”: { “name”: “Jane Doe” }
}’
修改已有的,增加没有的字段
curl -XPOST ‘localhost:9200/customer/external/1/_update?pretty’ -d ’
{
“doc”: { “name”: “Jane Doe”, “age”: 20 }
}’
已有基础上增加5
curl -XPOST ‘localhost:9200/customer/external/1/_update?pretty’ -d ’
{
“script” : “ctx._source.age += 5”
}’
ctx._source:当前数据源更新

删除id为2:curl -XDELETE ‘localhost:9200/customer/external/2?pretty’
批量新增
curl -XPOST ‘localhost:9200/customer/external/_bulk?pretty’ -d ’
{“index”:{“_id”:”1”}}
{“name”: “John Doe” }
{“index”:{“_id”:”2”}}
{“name”: “Jane Doe” }

更新第一个文档,删除第二个文档
curl -XPOST ‘localhost:9200/customer/external/_bulk?pretty’ -d ’
{“update”:{“_id”:”1”}}
{“doc”: { “name”: “John Doe becomes Jane Doe” } }
{“delete”:{“_id”:”2”}}

导入数据集
https://github.com/bly2k/files/blob/master/accounts.zip?raw=true
curl -XPOST ‘localhost:9200/bank/account/_bulk?pretty’ –data-binary “@accounts.json”
curl ‘localhost:9200/_cat/indices?v’

query
curl ‘localhost:9200/bank/_search?q=*&pretty’
使用json请求
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: { “match_all”: {} }
}’
查询一个结果
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: { “match_all”: {} },
“size”: 1
}’
查询11-20记录
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: { “match_all”: {} },
“from”: 10,
“size”: 10
}’
默认返回0-10条,并排序
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: { “match_all”: {} },
“sort”: { “balance”: { “order”: “desc” } }
}’

只查询account,balance ,_source数据源
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: { “match_all”: {} },
“_source”: [“account_number”, “balance”]
}’

查询编号为20
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: { “match”: { “account_number”: 20 } }
}’

查询地址包含mill或lane的地址
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: { “match”: { “address”: “mill lane” } }
}’
返回所有地址包括”mill lane”的文档
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: { “match_phrase”: { “address”: “mill lane” } }
}’
查询所有地址包括mill和lane的地址
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: {
“bool”: {
“must”: [
{ “match”: { “address”: “mill” } },
{ “match”: { “address”: “lane” } }
]
}
}
}’

查询所有地址包括mill或lane的地址
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: {
“bool”: {
“should”: [
{ “match”: { “address”: “mill” } },
{ “match”: { “address”: “lane” } }
]
}
}
}’

查询所有地址不包括mill也不包括lane的地址
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: {
“bool”: {
“must_not”: [
{ “match”: { “address”: “mill” } },
{ “match”: { “address”: “lane” } }
]
}
}
}’

匹配包括age=40但是不包括state为id
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: {
“bool”: {
“must”: [
{ “match”: { “age”: “40” } }
],
“must_not”: [
{ “match”: { “state”: “ID” } }
]
}
}

}’

范围查询between 20000 and 30000
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“query”: {
“bool”: {
“must”: { “match_all”: {} },
“filter”: {
“range”: {
“balance”: {
“gte”: 20000,
“lte”: 30000
}
}
}
}
}
}’

—————————-聚合运算
根据state分组,返回前10数据(默认),根据个数降序排序
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“size”: 0,
“aggs”: {
“group_by_state”: {
“terms”: {
“field”: “state”
}
}
}
}’
SELECT state, COUNT() FROM bank GROUP BY state ORDER BY COUNT() DESC

select state ,count(),avg(balance) from bak group by state order by count() desc
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“size”: 0, 不显示hits
“aggs”: {
“group_by_state”: {
“terms”: {
“field”: “state”
},
“aggs”: {
“average_balance”: {
“avg”: {
“field”: “balance”
}
}
}
}
}
}’

select state ,count(*),avg(balance) from bak group by state order by avg(balance) desc
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“size”: 0,
“aggs”: {
“group_by_state”: {
“terms”: {
“field”: “state”,
“order”: {
“average_balance”: “desc”
}
},
“aggs”: {
“average_balance”: {
“avg”: {
“field”: “balance”
}
}
}
}
}
}’

按照年龄(20-30,30-40,40-50)分组,按性别分组,算出balance平均值
curl -XPOST ‘localhost:9200/bank/_search?pretty’ -d ’
{
“size”: 0,
“aggs”: {
“group_by_age”: {
“range”: {
“field”: “age”,
“ranges”: [
{
“from”: 20,
“to”: 30
},
{
“from”: 30,
“to”: 40
},
{
“from”: 40,
“to”: 50
}
]
},
“aggs”: {
“group_by_gender”: {
“terms”: {
“field”: “gender”
},
“aggs”: {
“average_balance”: {
“avg”: {
“field”: “balance”
}
}
}
}
}
}
}
}’

防止刷新到磁盘
curl -XPUT ‘localhost:9200/_all/_settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“index”: {
“translog.disable_flush”: “true”
}
}

防止集群数据文件从这里移动到另一个节点
curl -XPUT ‘localhost:9200/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“transient”: {
“cluster.routing.allocation.enable”: “none”
}
}

刷新到磁盘,以及集群数据可以移动到另一个节点
curl -XPUT ‘localhost:9200/_all/_settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“index”: {
“translog.disable_flush”: “false”
}
}

curl -XPUT ‘localhost:9200/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“transient”: {
“cluster.routing.allocation.enable”: “all”
}
}

禁用关闭节点之前碎片化到其他节点
curl -XPUT ‘localhost:9200/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“transient”: {
“cluster.routing.allocation.enable”: “none”
}
}

碎片化分配,同步刷新
curl -XPOST ‘localhost:9200/_flush/synced?pretty’

升级节点
curl -XGET ‘localhost:9200/_cat/nodes?pretty’

加入节点后,碎片化分配
curl -XPUT ‘localhost:9200/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“transient”: {
“cluster.routing.allocation.enable”: “all”
}
}

查看碎片分配升级情况
curl -XGET ‘localhost:9200/_cat/health?pretty’

碎片分配时恢复请求
curl -XGET ‘localhost:9200/_cat/recovery?pretty’

禁用集群升级
curl -XPUT ‘localhost:9200/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“persistent”: {
“cluster.routing.allocation.enable”: “none”
}
}

集群升级
curl -XPUT ‘localhost:9200/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“persistent”: {
“cluster.routing.allocation.disable_allocation”: true,
“cluster.routing.allocation.enable”: “none”
}
}

使再能分配
curl -XPUT ‘localhost:9200/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“persistent”: {
“cluster.routing.allocation.enable”: “all”
}
}

集群升级
curl -XPUT ‘localhost:9200/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’
{
“persistent”: {
“cluster.routing.allocation.disable_allocation”: false,
“cluster.routing.allocation.enable”: “all”
}
}

==========================工具
输出漂亮格式:?pretty=true / ?format=yaml
可读输出:?human=false

减少elasticsearch响应输出
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
}
]
}
}

还支持通配符匹配
curl -XGET ‘localhost:9200/_nodes/stats?filter_path=nodes..ho
{
“nodes” : {
“lvJHed8uQQu4brS-SXKsNA” : {
“host” : “portable”
}
}
}

返回满足请求的每一段
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”
}
}
} ]
}
}
}
}

-===================
使用.和,分割减少响应
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
}
]
}
}

使用*匹配任何字段
curl -XGET ‘localhost:9200/_nodes/stats?filter_path=nodes..ho
{
“nodes” : {
“lvJHed8uQQu4brS-SXKsNA” : {
“host” : “portable”
}
}
}
任何每一段
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设置响应格式
防止body覆盖url的index参数:rest.action.multi.allow_explicit_index: false
action.auto_create_index:自动创建索引
index.mapper.dynamic:动态映射

读取版本
curl -XPUT ‘localhost:9200/twitter/tweet/1?version=2’ -d ‘{
“message” : “elasticsearch now has versioning support, double cool!”
}’

op_type=create:支持如果不在就添加,在则添加失败
curl -XPUT ‘http://localhost:9200/twitter/tweet/1?op_type=create’ -d ‘{
“user” : “kimchy”,
“post_date” : “2009-11-15T14:12:12”,
“message” : “trying out Elasticsearch”
}’
指定创建也可以使用如下uri
$ curl -XPUT ‘http://localhost:9200/twitter/tweet/1/_create’ -d ‘{
“user” : “kimchy”,
“post_date” : “2009-11-15T14:12:12”,
“message” : “trying out Elasticsearch”
}’
不指定id,会自动生成id,同时op_type自动设置创建
$ curl -XPOST ‘http://localhost:9200/twitter/tweet/’ -d ‘{
“user” : “kimchy”,
“post_date” : “2009-11-15T14:12:12”,
“message” : “trying out Elasticsearch”
}’
指定路由值,默认情况下使用id-hash,shard位置也是采用id-hash
$ curl -XPOST ‘http://localhost:9200/twitter/tweet?routing=kimchy’ -d ‘{
“user” : “kimchy”,
“post_date” : “2009-11-15T14:12:12”,
“message” : “trying out Elasticsearch”
}’
索引时指定其父,路由值取父的值
curlXPUTlocalhost:9200/blogs/blogtag/1122?parent=1111dtag:something, curl -XPUT localhost:9200/twitter/tweet/1?timestamp=2009-11-15T14%3A12%3A12 -d ‘{
“user” : “kimchy”,
“message” : “trying out Elasticsearch”
}’
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?”
}’

指定可超时5分钟,默认1分钟
$ curl -XPUT ‘http://localhost:9200/twitter/tweet/1?timeout=5m’ -d ‘{
“user” : “kimchy”,
“post_date” : “2009-11-15T14:12:12”,
“message” : “trying out Elasticsearch”
}’

检查文档
curl -XHEAD -i ‘http://localhost:9200/twitter/tweet/1
禁用实时获得数据
action.get.realtime:false
设置获取第一个文档id匹配的所有类型
_type=_all
默认返回source,除非你关闭
curl -XGET ‘http://localhost:9200/twitter/tweet/1?_source=false
source使用通配符包含或者排除field
curl -XGET ‘http://localhost:9200/twitter/tweet/1?_source_include=*.id&_source_exclude=entities’
指定包含,使用更短符号
curl -XGET ‘http://localhost:9200/twitter/tweet/1?_source=*.id,retweeted’
返回包含title,content文档
curl -XGET ‘http://localhost:9200/twitter/tweet/1?fields=title,content
忽略产生的字段
ignore_errors_on_generated_fields=true.
只获取source
curl -XGET ‘http://localhost:9200/twitter/tweet/1/_source
测试是否存在
curl -XHEAD -i ‘http://localhost:9200/twitter/tweet/1/_source
根据用户路由获取id为1值
curl -XGET ‘http://localhost:9200/twitter/tweet/1?routing=kimchy
控制偏好的碎片副本执行get请求
preference
_primary:只会执行主碎片
_local:优先本地分配碎片
refresh设置true,在get和搜索会刷新相关碎片根据
根据路由删除索引id为1值
$ curl -XDELETE ‘http://localhost:9200/twitter/tweet/1?routing=kimchy
删除父不影响子,删除所有子使用delete-by-query插件,删除子必须制定父id

============updateAPI
创建索引添加数据
curl -XPUT localhost:9200/test/type1/1 -d ‘{
“counter” : 1,
“tags” : [“red”]
}’
递增counter
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“script” : {
“inline”: “ctx._source.counter += count”,
“params” : {
“count” : 4
}
}
}’
添加标签,因为他是list
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“script” : {
“inline”: “ctx._source.tags += tag”,
“params” : {
“tag” : “blue”
}
}
}’
以下也可以根据ctx映射
_index, _type, _id, _version, _routing, _parent, _timestamp, _ttl.
增加新字段
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“script” : “ctx._source.name_of_new_field = \”value_of_new_field\””
}’
删除字段
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“script” : “ctx._source.remove(\”name_of_field\”)”
}’
包含blue删除,否则什么不做
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“script” : {
“inline”: “ctx._source.tags.contains(tag) ? ctx.op = \”delete\” : ctx.op = \”none\”“,
“params” : {
“tag” : “blue”
}
}
}’
部分文档合并到新文档中
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“doc” : {
“name” : “new_name”
}
}’
检测空更新:
detect_noop:false 没有改变总是更新
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“doc” : {
“name” : “new_name”
},
“detect_noop”: false
}’
文档不存在,插入。存在则执行脚本
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“script” : {
“inline”: “ctx._source.counter += count”,
“params” : {
“count” : 4
}
},
“upsert” : {
“counter” : 1
}
}’
无论怎样都执行脚本,而不是插入
curl -XPOST ‘localhost:9200/sessions/session/dh3sgudg8gsrgl/_update’ -d ‘{
“scripted_upsert”:true,
“script” : {
“id”: “my_web_session_summariser”,
“params” : {
“pageViewEvent” : {
“url”:”foo.com/bar”,
“response”:404,
“time”:”2014-01-01 12:32”
}
}
},
“upsert” : {}
}’
含有upsert作用
curl -XPOST ‘localhost:9200/test/type1/1/_update’ -d ‘{
“doc” : {
“name” : “new_name”
},
“doc_as_upsert” : true
}’

更新整个文档,而不是来源,获取快照
curl -XPOST ‘localhost:9200/twitter/_update_by_query?conflicts=proceed&pretty’
简单计数不会导致因为冲突_update_by_query 终止,2种设置方式
conflicts=proceed
“conflicts”: “proceed”
限制单一类型更新
curl -XPOST ‘localhost:9200/twitter/tweet/_update_by_query?conflicts=proceed&pretty’
用Query DSL更新整个文档
curl -XPOST ‘localhost:9200/twitter/_update_by_query?conflicts=proceed&pretty’ -H ‘Content-Type: application/json’ -d’
{
“query”: {
“term”: {
“user”: “kimchy”
}
}
}

使用脚本对象更新文件
curl -XPOST ‘localhost:9200/twitter/_update_by_query?pretty’ -H ‘Content-Type: application/json’ -d’
{
“script”: {
“inline”: “ctx._source.likes++”
},
“query”: {
“term”: {
“user”: “kimchy”
}
}
}

执行多个命令
curl -XPOST ‘localhost:9200/twitter,blog/tweet,post/_update_by_query?pretty’
使用路由限制匹配值,路由查询复制到滚动
curl -XPOST ‘localhost:9200/twitter/_update_by_query?routing=1&pretty’
默认滚动1000次,设置滚动值
curl -XPOST ‘localhost:9200/twitter/_update_by_query?scroll_size=100&pretty’
查询正在运作job状态
curl -XPOST ‘localhost:9200/_tasks/?pretty&detailed=true&action=*byquery&pretty’
取消任务
curl -XPOST ‘localhost:9200/_tasks/{task_id}/_cancel?pretty’
设置每秒请求值
curl -XPOST ‘localhost:9200/_update_by_query/{task_id}/_rethrottle?requests_per_second=unlimited&pretty’
//
创建没有动态映射索引且添加了值,如下添加一个映射值以从数据中提取更多字段
curl -XPUT ‘localhost:9200/test?pretty’ -H ‘Content-Type: application/json’ -d’
{
“mappings”: {
“test”: {
“dynamic”: false, 新的字段不会被索引,只存储在source
“properties”: {
“text”: {“type”: “string”}
}
}
}
}

curl -XPOST ‘localhost:9200/test/test?refresh&pretty’ -H ‘Content-Type: application/json’ -d’
{
“text”: “words words”,
“flag”: “bar”
}

curl -XPOST ‘localhost:9200/test/test?refresh&pretty’ -H ‘Content-Type: application/json’ -d’
{
“text”: “words words”,
“flag”: “foo”
}

更新映射添加新字段,必须重建所有文档与新字段
curl -XPUT ‘localhost:9200/test/_mapping/test?pretty’ -H ‘Content-Type: application/json’ -d’
{
“properties”: {
“text”: {“type”: “string”},
“flag”: {“type”: “string”, “analyzer”: “keyword”}
}
}

搜索不会获得任何东西,使用下面代码
curl -XPOST ‘localhost:9200/test/_search?filter_path=hits.total&pretty’ -H ‘Content-Type: application/json’ -d’
{
“query”: {
“match”: {
“flag”: “foo”
}
}
}

_update_by_query获取新映射
curl -XPOST ‘localhost:9200/test/_update_by_query?refresh&conflicts=proceed&pretty’
curl -XPOST ‘localhost:9200/test/_search?filter_path=hits.total&pretty’ -H ‘Content-Type: application/json’ -d’
{
“query”: {
“match”: {
“flag”: “foo”
}
}
}

===================get API
可以根据索引,类型,id,以及路由获取
curl ‘localhost:9200/_mget’ -d ‘{
“docs” : [
{
“_index” : “test”,
“_type” : “type”,
“_id” : “1”
},
{
“_index” : “test”,
“_type” : “type”,
“_id” : “2”
}
]
}’
index添加到url查询
curl ‘localhost:9200/test/_mget’ -d ‘{
“docs” : [
{
“_type” : “type”,
“_id” : “1”
},
{
“_type” : “type”,
“_id” : “2”
}
]
}’
添加url和type到uri查询
curl ‘localhost:9200/test/type/_mget’ -d ‘{
“docs” : [
{
“_id” : “1”
},
{
“_id” : “2”
}
]
}’
使用ids简化请求
curl ‘localhost:9200/test/type/_mget’ -d ‘{
“ids” : [“1”, “2”]
}’
_type可选,设置_all或者空,取第一个文档匹配的所有类型,
如下将返回2个id为1的不同类型的字段信息
curl ‘localhost:9200/test/_mget’ -d ‘{
“ids” : [“1”, “1”]
}’
使用source,默认source检索所有,可以检索部分字段,以及设置包含那个,不包含那个
curl ‘localhost:9200/_mget’ -d ‘{
“docs” : [
{
“_index” : “test”,
“_type” : “type”,
“_id” : “1”,
“_source” : false
},
{
“_index” : “test”,
“_type” : “type”,
“_id” : “2”,
“_source” : [“field3”, “field4”]
},
{
“_index” : “test”,
“_type” : “type”,
“_id” : “3”,
“_source” : {
“include”: [“user”],
“exclude”: [“user.location”]
}
}
]
}’
指定获取字段
curl ‘localhost:9200/_mget’ -d ‘{
“docs” : [
{
“_index” : “test”,
“_type” : “type”,
“_id” : “1”,
“fields” : [“field1”, “field2”]
},
{
“_index” : “test”,
“_type” : “type”,
“_id” : “2”,
“fields” : [“field3”, “field4”]
}
]
}’
uri上指定默认字段,传参指定field会覆盖
curl ‘localhost:9200/test/type/_mget?fields=field1,field2’ -d ‘{
“docs” : [
{
“_id” : “1”
},
{
“_id” : “2”,
“fields” : [“field3”, “field4”]
}
]
}’
指定路由值作为参数
curl ‘localhost:9200/_mget?routing=key1’ -d ‘{
“docs” : [
{
“_index” : “test”,
“_type” : “type”,
“_id” : “1”,
“_routing” : “key2”
},
{
“_index” : “test”,
“_type” : “type”,
“_id” : “2”
}
]
}’

=========================buli api|Reindex API

====================Term Vectors
返回信息和统计领域的一个特定的文档,默认实时realtime=false,可存储在索引中或用户指定
支持通配符匹配
默认返回术语信息,字段统计,没有术语统计
curl -XGET ‘http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true
curl -XGET ‘http://localhost:9200/twitter/tweet/1/_termvectors?fields=text,…’
创建索引,存储术语向量,有效载荷等
curl -s -XPUT ‘http://localhost:9200/twitter/’ -d ‘{
“mappings”: {
“tweet”: {
“properties”: {
“text”: {
“type”: “string”,
“term_vector”: “with_positions_offsets_payloads”,
“store” : true,
“analyzer” : “fulltext_analyzer”
},
“fullname”: {
“type”: “string”,
“term_vector”: “with_positions_offsets_payloads”,
“analyzer” : “fulltext_analyzer”
}
}
}
},
“settings” : {
“index” : {
“number_of_shards” : 1,
“number_of_replicas” : 0
},
“analysis”: {
“analyzer”: {
“fulltext_analyzer”: {
“type”: “custom”,
“tokenizer”: “whitespace”,
“filter”: [
“lowercase”,
“type_as_payload”
]
}
}
}
}
}’
添加2文档
curl -XPUT ‘http://localhost:9200/twitter/tweet/1?pretty=true’ -d ‘{
“fullname” : “John Doe”,
“text” : “twitter test test test ”
}’

curl -XPUT 'http://localhost:9200/twitter/tweet/2?pretty=true' -d '{
  "fullname" : "Jane Doe",
  "text" : "Another twitter test ..."
}'

要求返回文本字段所有信息以及统计信息
curl -XGET ‘http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true’ -d
‘{
“fields” : [“text”],
“offsets” : true,
“payloads” : true,
“positions” : true,
“term_statistics” : true,
“field_statistics” : true
}’
返回文档1中字段的所有信息和统计信息
curl -XGET ‘http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true’ -d ‘{
“fields” : [“text”, “some_field_without_term_vectors”],
“offsets” : true,
“positions” : true,
“term_statistics” : true,
“field_statistics” : true
}’
自动生成向量
curl -XGET ‘http://localhost:9200/twitter/tweet/_termvectors’ -d ‘{
“doc” : {
“fullname” : “John Doe”,
“text” : “twitter test test test”
}
}’
指定分析仪
curl -XGET ‘http://localhost:9200/twitter/tweet/_termvectors’ -d ‘{
“doc” : {
“fullname” : “John Doe”,
“text” : “twitter test test test”
},
“fields”: [“fullname”],
“per_field_analyzer” : {
“fullname”: “keyword”
}
}’

表达式过滤
GET /imdb/movies/_termvectors
{
“doc”: {
“plot”: “When wealthy industrialist Tony Stark is forced to build an armored suit after a life-threatening incident, he ultimately decides to use its technology to fight against evil.”
},
“term_statistics” : true,
“field_statistics” : true,
“dfs”: true,
“positions”: false,
“offsets”: false,
“filter” : {
“max_num_terms” : 3,
“min_term_freq” : 1,
“min_doc_freq” : 1
}
}
获取多个词向量
curl ‘localhost:9200/_mtermvectors’ -d ‘{
“docs”: [
{
“_index”: “testidx”,
“_type”: “test”,
“_id”: “2”,
“term_statistics”: true
},
{
“_index”: “testidx”,
“_type”: “test”,
“_id”: “1”,
“fields”: [
“text”
]
}
]
}’
索引添加uri
curl ‘localhost:9200/testidx/_mtermvectors’ -d ‘{
“docs”: [
{
“_type”: “test”,
“_id”: “2”,
“fields”: [
“text”
],
“term_statistics”: true
},
{
“_type”: “test”,
“_id”: “1”
}
]
}’
索引类型添加到uri
curl ‘localhost:9200/testidx/test/_mtermvectors’ -d ‘{
“docs”: [
{
“_id”: “2”,
“fields”: [
“text”
],
“term_statistics”: true
},
{
“_id”: “1”
}
]
}’
简化请求
curl ‘localhost:9200/testidx/test/_mtermvectors’ -d ‘{
“ids” : [“1”, “2”],
“parameters”: {
“fields”: [
“text”
],
“term_statistics”: true,

}
}’
词向量提供文档生成
curl ‘localhost:9200/_mtermvectors’ -d ‘{
“docs”: [
{
“_index”: “testidx”,
“_type”: “test”,
“doc” : {
“fullname” : “John Doe”,
“text” : “twitter test test test”
}
},
{
“_index”: “testidx”,
“_type”: “test”,
“doc” : {
“fullname” : “Jane Doe”,
“text” : “Another twitter test …”
}
}
]
}’

=======================search api

$ curl -XPOST ‘http://localhost:9200/twitter/tweet?routing=kimchy’ -d ‘{
“user” : “kimchy”,
“postDate” : “2009-11-15T14:12:12”,
“message” : “trying out Elasticsearch”
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值