Skip to content

Commit 581e9ba

Browse files
authored
Merge pull request #27 from cloudAndMonkey/master
支持多数据源、elasticsearch-sql、elasticsearch增删改查
2 parents e1ea3db + b33c554 commit 581e9ba

17 files changed

+2168
-0
lines changed

Diff for: APIJSONDemo-MultiDataSource-Elasticsearch/README.md

+383
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,383 @@
1+
# APIJSONDemo
2+
3+
## 1、支持多数据源
4+
5+
数据源解析顺序:
6+
7+
- [ ] 对象@datasource
8+
9+
- [ ] 全局 @datasource
10+
11+
- [ ] 应用默认 @datasource
12+
13+
```json
14+
{
15+
// "@datasource": "db2" 全局
16+
"@post": {
17+
"User:aa": {
18+
"@datasource": "db2" // 对象
19+
},
20+
"User_address[]": {
21+
"@datasource": "db2"
22+
}
23+
},
24+
"User:aa":{
25+
"username":"test-3",
26+
"password": "233223",
27+
"state": 1
28+
},
29+
"ES_blog:a": {
30+
"@datasource": "elasticSearch",
31+
"title.keyword": "test-2"
32+
},
33+
"User_address[]": [
34+
{
35+
"user_id@": "User:aa/id",
36+
"addr": "ddd",
37+
"count@": "ES_blog:a/count"
38+
},
39+
{
40+
"user_id@": "User:aa/id",
41+
"addr": "ddd1",
42+
"count@": "ES_blog:a/count"
43+
}
44+
],
45+
"@explain": true
46+
}
47+
```
48+
49+
![image](https://user-images.githubusercontent.com/12228225/207245545-277ba9a6-e87f-42b3-af55-9d6a37384a1e.png)
50+
51+
## 2、集成elasticsearch-sql
52+
53+
换成xpack, 也一样
54+
55+
应用导入: elasticsearch-sql-7.17.5.0.jar
56+
57+
## 3、apijson支持elasticsearch功能点
58+
59+
新增、修改、删除、查询
60+
61+
## 4、elasticsearch-sql不支持RLIKE
62+
63+
![image](https://user-images.githubusercontent.com/12228225/207245701-ea2560a9-2389-4953-a568-9e85adfb15ad.png)
64+
65+
## 5、apijson支持字段 .keyword
66+
67+
```
68+
{
69+
"@datasource": "elasticSearch",
70+
"ES_blog:aa":{
71+
"title.keyword$": "%test-2",
72+
"content": "u-c-2",
73+
"url": "u-u-2",
74+
"postdate": "2008-12-11",
75+
"count": 1
76+
},
77+
"tag": "ES_blog",
78+
"@explain": true
79+
}
80+
```
81+
82+
83+
84+
## 4、示例
85+
86+
### 单条插入
87+
88+
```
89+
http://localhost:8080/post
90+
91+
{
92+
"@datasource": "elasticSearch",
93+
"ES_blog:aa":{
94+
"title":"test-1",
95+
"author": "a-1",
96+
"content": "c-1",
97+
"url": "u-1",
98+
"postdate": "2018-12-11",
99+
"count": 1
100+
},
101+
"tag": "ES_blog",
102+
"@explain": true
103+
}
104+
105+
```
106+
107+
108+
109+
110+
elasticsearch查询插入的数据:
111+
112+
GET /es_blog/_doc/5b77b103-0231-42c3-a6cf-a0cb933d3dda
113+
114+
115+
### 批量插入
116+
117+
```json
118+
http://localhost:8080/post
119+
120+
{
121+
"@datasource": "elasticSearch",
122+
"ES_blog:aa[]": [
123+
{
124+
"title":"test-1",
125+
"author": "a-1",
126+
"content": "c-1",
127+
"url": "u-1",
128+
"postdate": "2018-12-11",
129+
"count": 1
130+
},
131+
{
132+
"title":"test-2",
133+
"author": "a-2",
134+
"content": "c-2",
135+
"url": "u-2",
136+
"postdate": "2018-12-11",
137+
"count": 2
138+
},
139+
{
140+
"title":"test-3",
141+
"author": "a-3",
142+
"content": "c-3",
143+
"url": "u-3",
144+
"postdate": "2018-12-11",
145+
"count": 3
146+
}
147+
],
148+
"tag": "ES_blog[]",
149+
"@explain": true
150+
}
151+
152+
```
153+
154+
elasticsearch查询插入的数据:
155+
156+
GET /es_blog/_search
157+
158+
159+
### id修改
160+
161+
```json
162+
http://localhost:8080/put
163+
164+
{
165+
"@datasource": "elasticSearch",
166+
"ES_blog:aa":{
167+
"id": "5b77b103-0231-42c3-a6cf-a0cb933d3dda",
168+
"title":"u-test-1",
169+
"author": "u-a-1",
170+
"content": "u-c-1",
171+
"url": "u-u-1",
172+
"postdate": "2018-12-10",
173+
"count": 9
174+
},
175+
"tag": "ES_blog",
176+
"@explain": true
177+
}
178+
```
179+
180+
181+
### 非id修改
182+
183+
```
184+
http://localhost:8080/put
185+
{
186+
"@datasource": "elasticSearch",
187+
"ES_blog:aa":{
188+
"title~":"u-test-1",
189+
"author": "u1-a-2",
190+
"content": "u1-c-2",
191+
"url": "u1-u-2",
192+
"postdate": "2028-12-11",
193+
"count": 1
194+
},
195+
"tag": "ES_blog",
196+
"@explain": true
197+
}
198+
199+
200+
{
201+
"@datasource": "elasticSearch",
202+
"ES_blog:aa":{
203+
"title~":"test-3",
204+
"author~": "u3-a-2",
205+
"content": "u1-c-2",
206+
"url": "u1-u-2",
207+
"postdate": "2028-12-11",
208+
"count": 1,
209+
"@combine":"title~ | author~"
210+
},
211+
"tag": "ES_blog",
212+
"@explain": true
213+
}
214+
215+
{
216+
"@datasource": "elasticSearch",
217+
"ES_blog:aa":{
218+
"count{}":[1,4],
219+
"content": "u-c-2",
220+
"url": "u-u-2",
221+
"postdate": "2008-12-11",
222+
"count": 1
223+
},
224+
"tag": "ES_blog",
225+
"@explain": true
226+
}
227+
228+
{
229+
"@datasource": "elasticSearch",
230+
"ES_blog:aa":{
231+
"title$": "%test",
232+
"content": "u-c-2",
233+
"url": "u-u-2",
234+
"postdate": "2008-12-11",
235+
"count": 1
236+
},
237+
"tag": "ES_blog",
238+
"@explain": true
239+
}
240+
241+
242+
{
243+
"@datasource": "elasticSearch",
244+
"ES_blog:aa":{
245+
"postdate%":"2007-10-01,2018-10-01",
246+
"content": "u-c-2",
247+
"url": "u-u-2",
248+
"postdate": "2008-12-11",
249+
"count": 1
250+
},
251+
"tag": "ES_blog",
252+
"@explain": true
253+
}
254+
```
255+
256+
257+
### 批量修改
258+
259+
```
260+
http://localhost:8080/put
261+
{
262+
"@datasource": "elasticSearch",
263+
"ES_blog:aa[]": [
264+
{
265+
"title~":"test-1",
266+
"author": "u3-a-2",
267+
"content": "u3-c-2",
268+
"url": "u3-u-2",
269+
"postdate": "2038-12-11",
270+
"count": 1
271+
},
272+
{
273+
"title~":"test-2",
274+
"author": "u-a-3",
275+
"content": "u-c-3",
276+
"url": "u-u-3",
277+
"postdate": "2008-12-11",
278+
"count": 4
279+
}
280+
],
281+
"tag": "ES_blog[]",
282+
"explain": true
283+
}
284+
```
285+
286+
### id删除
287+
288+
```
289+
{
290+
"@datasource": "elasticSearch",
291+
"ES_blog:del": {
292+
"id": "043a7511-296b-43b5-9f12-966dd86299d1"
293+
},
294+
"tag": "ES_blog",
295+
"explain": true
296+
}
297+
```
298+
299+
300+
301+
### 非id条件删除
302+
303+
```
304+
http://localhost:8080/delete
305+
306+
{
307+
"@datasource": "elasticSearch",
308+
"ES_blog:del": {
309+
"title": "test-2"
310+
},
311+
"tag": "ES_blog",
312+
"explain": true
313+
}
314+
315+
{
316+
"@datasource": "elasticSearch",
317+
"ES_blog:del": {
318+
"count{}":[2,4]
319+
},
320+
"tag": "ES_blog",
321+
"explain": true
322+
}
323+
```
324+
325+
326+
### 批量删除
327+
328+
```
329+
{
330+
"@datasource": "elasticSearch",
331+
"ES_blog:del": {
332+
"id{}": ["f41e3010-c410-45a0-b41a-33afbc1e4ef8","d765de31-2fc8-40e5-9430-277bf7e5f91b"]
333+
},
334+
"tag": "ES_blog",
335+
"explain": true
336+
}
337+
```
338+
339+
### 查询单条记录
340+
341+
```
342+
{
343+
"ES_blog:a": {
344+
"@datasource": "elasticSearch",
345+
"id": "4862927d-9a38-47c9-9cfc-5b3e9db38d30"
346+
},
347+
"@explain": true
348+
}
349+
```
350+
351+
### 分页查询
352+
353+
```
354+
{
355+
"[]": {
356+
"ES_blog": {
357+
"@datasource": "elasticSearch"
358+
},
359+
"page": 0,
360+
"count": 2,
361+
"query": 2
362+
},
363+
"total@": "/[]/total"
364+
}
365+
366+
```
367+
368+
369+
### 分组查询
370+
371+
```
372+
{
373+
"@datasource": "elasticSearch",
374+
"[]": {
375+
"count": 5,
376+
"ES_blog":{
377+
"@column":"count;sum(count):sum",
378+
"@group":"count"
379+
}
380+
}
381+
}
382+
```
383+
Binary file not shown.

0 commit comments

Comments
 (0)