spark、es、java精确匹配

来源:互联网 发布:查看数据库命令 编辑:程序博客网 时间:2024/06/08 08:43

1、新建一个索引waybill

curl -XPUT http://10.118.58.67:9200/waybill

2、为索引添加type及type的mapping,注意:对于需要完全精确匹配的字段需要设置为string类型、index方式为not_analyzed。字段类型创建后无法修改。

curl -XPUT http://10.116.50.223:9200/waybill/details/_mapping?pretty-d '

{"details":{"properties":

{"backnewway":{"type":"string","index":"not_analyzed"},

"barscantm":{"type":"long"},

"calhour":{"type":"long"},"caltime":{"type":"long"},

"collectondelivery":{"type":"string","index":"not_analyzed"},

"consigneddt":{"type":"long"},"consignedtm":{"type":"long"},

"custno":{"type":"string","index":"not_analyzed"},

"describle":{"type":"string","index":"not_analyzed"},

"destname":{"type":"string","index":"not_analyzed"},

"destprovince":{"type":"string","index":"not_analyzed"},

"erpno":{"type":"string","index":"not_analyzed"},

"group_code":{"type":"string","index":"not_analyzed"},

"md5str":{"type":"string"},"meterageweightqty":{"type":"float"},

"opcode":{"type":"string","index":"not_analyzed"},

"paymenttype":{"type":"string","index":"not_analyzed"},

"realweightqty":{"type":"float"},

"returntm":{"type":"long"},"signbacktm":{"type":"long"},

"signbackwaybill":{"type":"string","index":"not_analyzed"},

"signintm":{"type":"long"},"signstate":{"type":"string","index":"not_analyzed"},

"sourcename":{"type":"string","index":"not_analyzed"},

"sourcewaybill":{"type":"string","index":"not_analyzed"},

"stayreason":{"type":"string","index":"not_analyzed"},

"staytype":{"type":"string","index":"not_analyzed"},

"staywhycode":{"type":"string","index":"not_analyzed"},"subsize":{"type":"long"},

"switchcom":{"type":"string","index":"not_analyzed"},"switchtm":{"type":"long"},

"switchway":{"type":"string","index":"not_analyzed"},"topic":{"type":"string","index":"not_analyzed"},

"waybill":{"type":"string","index":"not_analyzed"}}}}'

3、设置默认分页大小

curl -XPUT http://10.118.58.67:9200/waybill/_settings?pretty -d '

{"max_result_window":500000}'

4、按照设置的mapping写df数据

resDf.write.mode(SaveMode.Append)

     .format("org.elasticsearch.spark.sql")

     .save("waybill/details")

4、java读取es数据

配置settings,添加es master节点。

QueryBuilder、BoolQueryBuilder、addSort、setSize、execute

原创粉丝点击