es_post ()

阅读(3223) 标签: 执行post, 序表, 游标,

描述:

执行post指令,返回序表或者游标。

语法:

es_post(fd, endpoint, entityheader)

备注:

外部库函数,外部库的使用请参考《外部库使用指南》。

通过post指令查询,缺省最大返回10条记录。若返回结果集json中包括多个_index,则采用展开方式显示。entity参数可省略

选项:

@c

游标查询。

@f

支持entity参数为文件。

参数:

fd

restclient对象。

endpoint

Rest Api 参数的地址。

entity

通过 http body 传递的参数,参数可以是符合json格式的字符串或内容为符合json格式的文件名。

header

一个可变参数,可以传入对应的 http 头信息,参数为符合json格式的键值类型字符串。

返回值:

序表/游标

示例:

 

A

 

1

=es_open("localhost:9200 ","user":"un1234")

连接ES server

2

=es_post(A1,"/accounts/_search?q=user:kimchy")

indexbank中查询用户名为kimchy的记录

3

=es_post(A1,"/_all/_search?q=_id:5")

跨库查询_id5的记录

4

=es_post@c(A1,"/accounts/person/_search")

游标形式查询indexaccountstypeperson的记录

5

=A4.fetch()

返回游标记录

6

=es_post@f(A1,"/bank/person/_search","D:/entity_post_accounts.txt")

entity参数为文件时,查询_gender=”F”/bank/person下的记录,并作排序处理。

注:文件entity_post_accounts.txt中的内容:

{

 "query" : {

"match" : { "gender" : "F" }

},

"track_scores": true,

"sort" : [

{ "account_number" : {"order" : "desc"} },

{ "firstname" : "desc" },

{ "lastname" : "desc" }

]

}