java的elasticsearch搜尋引擎工具類

2021-09-24 05:41:24 字數 3867 閱讀 1320

去年寫的乙個小工具類,整理了一下分享出來

源設計**於csdn某篇博文,這個工具類是在那位博主基礎上新增了一些功能,找了很久找不到那篇博文位址了,十分抱歉,在此宣告一下。如果有找到的朋友可以跟我說,我好把鏈結加上。

這是乙個簡陋的es工具類

elasticsearch 6.0.0

test=, "num": , "begin_date": } }
string index =

"test"

;string type =

"testtype"

;elasticsearchservice elasticsearchservice =

newelasticsearchservice()

;elasticsearchservice.

createindex

(index, type)

;

一共有四種新增資料的方式

string index =

"test"

;string type =

"testtype"

;elasticsearchservice elasticsearchservice =

newelasticsearchservice()

;map

data =

newhashmap

();map

param =

newhashmap

();param.

put(

"name"

,"張三");

param.

put(

"num",1

);param.

put(

"begin_date"

,"2019-02-11 10:10:10");

mapparam1 =

newhashmap

();param1.

put(

"name"

,"張三四");

param1.

put(

"num",2

);param1.

put(

"begin_date"

,"2019-02-10 06:06:06");

data.

put(digestutils.

md5hex

(json.

tojsonstring

(param)

), param)

;data.

put(digestutils.

md5hex

(json.

tojsonstring

(param1)

), param1)

;elasticsearchservice.

bulkinsertdataprocesser

(index, type, data)

;

term
esquerybuilderconstructor esbc =

newesquerybuilderconstructor()

;esquerybuilders esb =

newesquerybuilders()

;esb.

term

("name"

,"張三");

esbc.

must

(esb)

;map

data = ess.

search

(index, type, esbc,

newstring

);data.

foreach

((key,value)

->

);

esquerybuilderconstructor 分為must,should,mustnot

must 必須匹配 and

should 可匹配 or

mustnot 必不匹配 非 and

match

esquerybuilderconstructor esbc =

newesquerybuilderconstructor()

;esquerybuilders esb =

newesquerybuilders()

;esb.

match

("name"

,"張三");

esbc.

must

(esb)

;map

data = ess.

search

(index, type, esbc,

newstring

);data.

foreach

((key,value)

->

);

後面跟es提供的型別一樣,請參閱es查詢方式,這裡就不一一舉例了

esquerybuilderconstructor esbc =

newesquerybuilderconstructor()

;esquerybuilders esb =

newesquerybuilders()

;esgroupby esgb =

newesgroupby

("num");

esgb.

desc(2

);esbc.

setesgroupby

(esgb)

;

desc,esc中1:by_count2:by_key

分組日期需要增加一段

esgb.

setsearchway

(searchway, format, interval)

;

searchway 預設為1

1:search_term,2:search_date

esquerybuilderconstructor esbc =

newesquerybuilderconstructor()

;esquerybuilders esb =

newesquerybuilders()

;esgroupby esgb =

newesgroupby

("num");

esgb.

min(

"num"

,"min");

esbc.

setesgroupby

(esgb)

;

elasticsearchservice.

getsearchdatabyscrolls

(indexfrom, indexto, type)

;

indexfrom: 源索引

indexto: 目標索引

type: 共用的型別名必須相同

elasticsearchservice.

deleteindex

(index)

;

elasticsearchservice.

delbyquery

(index,map,notmap)

;

index 索引名

map 暫時只支援 must->term

notmap 同理 mustnot->term

將查詢到的資料刪除

這裡是git位址

基於Python操作ElasticSearch

python 2.7 es依賴包 pyelasticsearch elasticsearch 5.5.1 6.0.1 作業系統 windows 10 centos 7 本文主要就es基本的crud操作做以歸納整理,es官方對python的依賴支援有很多,eg pyelasticsearch escl...

基於Python操作ElasticSearch

python 2.7 es依賴包 pyelasticsearch elasticsearch 5.5.1 6.0.1 作業系統 windows 10 centos 7 本文主要就es基本的crud操作做以歸納整理,es官方對python的依賴支援有很多,eg pyelasticsearch escl...

Docker環境安裝Elasticsearch

docker pull elasticsearch 6.4.0 修改虛擬記憶體區域大小,否則會因為過小而無法啟動 sysctl w vm.max map count 262144 使用docker命令啟動 docker run p 9200 9200 p 9300 9300 name elastic...