Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4fc8ae6

Browse files
支持多数据源、elasticsearch-sql、elasticsearch增删改查
具体使用请参见README.md
1 parent e1ea3db commit 4fc8ae6

17 files changed

+2177
-0
lines changed
Lines changed: 397 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,397 @@
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-20221213105328227](/Users/xy/Library/Application Support/typora-user-images/image-20221213105328227.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-20221213141141037](/Users/xy/Library/Application Support/typora-user-images/image-20221213141141037.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+
![image-20221213105649445](/Users/xy/Library/Application Support/typora-user-images/image-20221213105649445.png)
108+
109+
110+
111+
elasticsearch查询插入的数据:
112+
113+
GET /es_blog/_doc/5b77b103-0231-42c3-a6cf-a0cb933d3dda
114+
115+
![image-20221213105850231](/Users/xy/Library/Application Support/typora-user-images/image-20221213105850231.png)
116+
117+
### 批量插入
118+
119+
```json
120+
http://localhost:8080/post
121+
122+
{
123+
"@datasource": "elasticSearch",
124+
"ES_blog:aa[]": [
125+
{
126+
"title":"test-1",
127+
"author": "a-1",
128+
"content": "c-1",
129+
"url": "u-1",
130+
"postdate": "2018年12月11日",
131+
"count": 1
132+
},
133+
{
134+
"title":"test-2",
135+
"author": "a-2",
136+
"content": "c-2",
137+
"url": "u-2",
138+
"postdate": "2018年12月11日",
139+
"count": 2
140+
},
141+
{
142+
"title":"test-3",
143+
"author": "a-3",
144+
"content": "c-3",
145+
"url": "u-3",
146+
"postdate": "2018年12月11日",
147+
"count": 3
148+
}
149+
],
150+
"tag": "ES_blog[]",
151+
"@explain": true
152+
}
153+
154+
```
155+
156+
![image-20221213104938108](/Users/xy/Library/Application Support/typora-user-images/image-20221213104938108.png)
157+
158+
elasticsearch查询插入的数据:
159+
160+
GET /es_blog/_search
161+
162+
![image-20221213105443909](/Users/xy/Library/Application Support/typora-user-images/image-20221213105443909.png)
163+
164+
### id修改
165+
166+
```json
167+
http://localhost:8080/put
168+
169+
{
170+
"@datasource": "elasticSearch",
171+
"ES_blog:aa":{
172+
"id": "5b77b103-0231-42c3-a6cf-a0cb933d3dda",
173+
"title":"u-test-1",
174+
"author": "u-a-1",
175+
"content": "u-c-1",
176+
"url": "u-u-1",
177+
"postdate": "2018年12月10日",
178+
"count": 9
179+
},
180+
"tag": "ES_blog",
181+
"@explain": true
182+
}
183+
```
184+
185+
![image-20221213110113376](/Users/xy/Library/Application Support/typora-user-images/image-20221213110113376.png)
186+
187+
188+
189+
![image-20221213110132755](/Users/xy/Library/Application Support/typora-user-images/image-20221213110132755.png)
190+
191+
### 非id修改
192+
193+
```
194+
http://localhost:8080/put
195+
{
196+
"@datasource": "elasticSearch",
197+
"ES_blog:aa":{
198+
"title~":"u-test-1",
199+
"author": "u1-a-2",
200+
"content": "u1-c-2",
201+
"url": "u1-u-2",
202+
"postdate": "2028年12月11日",
203+
"count": 1
204+
},
205+
"tag": "ES_blog",
206+
"@explain": true
207+
}
208+
209+
210+
{
211+
"@datasource": "elasticSearch",
212+
"ES_blog:aa":{
213+
"title~":"test-3",
214+
"author~": "u3-a-2",
215+
"content": "u1-c-2",
216+
"url": "u1-u-2",
217+
"postdate": "2028年12月11日",
218+
"count": 1,
219+
"@combine":"title~ | author~"
220+
},
221+
"tag": "ES_blog",
222+
"@explain": true
223+
}
224+
225+
{
226+
"@datasource": "elasticSearch",
227+
"ES_blog:aa":{
228+
"count{}":[1,4],
229+
"content": "u-c-2",
230+
"url": "u-u-2",
231+
"postdate": "2008年12月11日",
232+
"count": 1
233+
},
234+
"tag": "ES_blog",
235+
"@explain": true
236+
}
237+
238+
{
239+
"@datasource": "elasticSearch",
240+
"ES_blog:aa":{
241+
"title$": "%test",
242+
"content": "u-c-2",
243+
"url": "u-u-2",
244+
"postdate": "2008年12月11日",
245+
"count": 1
246+
},
247+
"tag": "ES_blog",
248+
"@explain": true
249+
}
250+
251+
252+
{
253+
"@datasource": "elasticSearch",
254+
"ES_blog:aa":{
255+
"postdate%":"2007年10月01日,2018年10月01日",
256+
"content": "u-c-2",
257+
"url": "u-u-2",
258+
"postdate": "2008年12月11日",
259+
"count": 1
260+
},
261+
"tag": "ES_blog",
262+
"@explain": true
263+
}
264+
```
265+
266+
![image-20221213120359815](/Users/xy/Library/Application Support/typora-user-images/image-20221213120359815.png)
267+
268+
### 批量修改
269+
270+
```
271+
http://localhost:8080/put
272+
{
273+
"@datasource": "elasticSearch",
274+
"ES_blog:aa[]": [
275+
{
276+
"title~":"test-1",
277+
"author": "u3-a-2",
278+
"content": "u3-c-2",
279+
"url": "u3-u-2",
280+
"postdate": "2038年12月11日",
281+
"count": 1
282+
},
283+
{
284+
"title~":"test-2",
285+
"author": "u-a-3",
286+
"content": "u-c-3",
287+
"url": "u-u-3",
288+
"postdate": "2008年12月11日",
289+
"count": 4
290+
}
291+
],
292+
"tag": "ES_blog[]",
293+
"explain": true
294+
}
295+
```
296+
297+
### id删除
298+
299+
```
300+
{
301+
"@datasource": "elasticSearch",
302+
"ES_blog:del": {
303+
"id": "043a7511-296b-43b5-9f12-966dd86299d1"
304+
},
305+
"tag": "ES_blog",
306+
"explain": true
307+
}
308+
```
309+
310+
311+
312+
### 非id条件删除
313+
314+
```
315+
http://localhost:8080/delete
316+
317+
{
318+
"@datasource": "elasticSearch",
319+
"ES_blog:del": {
320+
"title": "test-2"
321+
},
322+
"tag": "ES_blog",
323+
"explain": true
324+
}
325+
326+
{
327+
"@datasource": "elasticSearch",
328+
"ES_blog:del": {
329+
"count{}":[2,4]
330+
},
331+
"tag": "ES_blog",
332+
"explain": true
333+
}
334+
```
335+
336+
![image-20221213115535006](/Users/xy/Library/Application Support/typora-user-images/image-20221213115535006.png)
337+
338+
### 批量删除
339+
340+
```
341+
{
342+
"@datasource": "elasticSearch",
343+
"ES_blog:del": {
344+
"id{}": ["f41e3010-c410-45a0-b41a-33afbc1e4ef8","d765de31-2fc8-40e5-9430-277bf7e5f91b"]
345+
},
346+
"tag": "ES_blog",
347+
"explain": true
348+
}
349+
```
350+
351+
### 查询单条记录
352+
353+
```
354+
{
355+
"ES_blog:a": {
356+
"@datasource": "elasticSearch",
357+
"id": "4862927d-9a38-47c9-9cfc-5b3e9db38d30"
358+
},
359+
"@explain": true
360+
}
361+
```
362+
363+
### 分页查询
364+
365+
```
366+
{
367+
"[]": {
368+
"ES_blog": {
369+
"@datasource": "elasticSearch"
370+
},
371+
"page": 0,
372+
"count": 2,
373+
"query": 2
374+
},
375+
"total@": "/[]/total"
376+
}
377+
378+
```
379+
380+
![image-20221213140810462](/Users/xy/Library/Application Support/typora-user-images/image-20221213140810462.png)
381+
382+
### 分组查询
383+
384+
```
385+
{
386+
"@datasource": "elasticSearch",
387+
"[]": {
388+
"count": 5,
389+
"ES_blog":{
390+
"@column":"count;sum(count):sum",
391+
"@group":"count"
392+
}
393+
}
394+
}
395+
```
396+
397+
![image-20221213140933538](/Users/xy/Library/Application Support/typora-user-images/image-20221213140933538.png)
359 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /