Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
6767ae3d
Commit
6767ae3d
authored
Oct 20, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
es delete
parent
e37a3f77
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
36 deletions
+34
-36
ESHelper.java
.../main/java/com/tanpu/community/service/base/ESHelper.java
+34
-36
No files found.
community-service/src/main/java/com/tanpu/community/service/base/ESHelper.java
View file @
6767ae3d
package
com
.
tanpu
.
community
.
service
.
base
;
import
com.tanpu.common.util.JsonUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.exception.ExceptionUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -9,15 +10,19 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import
org.apache.http.client.CredentialsProvider
;
import
org.apache.http.impl.client.BasicCredentialsProvider
;
import
org.apache.http.impl.nio.client.HttpAsyncClientBuilder
;
import
org.elasticsearch.action.ActionRequest
;
import
org.elasticsearch.action.delete.DeleteRequest
;
import
org.elasticsearch.action.delete.DeleteResponse
;
import
org.elasticsearch.action.index.IndexRequest
;
import
org.elasticsearch.action.index.IndexResponse
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RestClient
;
import
org.elasticsearch.client.RestClientBuilder
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.common.xcontent.XContentType
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.MatchPhraseQueryBuilder
;
import
org.elasticsearch.index.query.MatchQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.rest.RestStatus
;
import
org.elasticsearch.search.SearchHit
;
...
...
@@ -25,12 +30,8 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.elasticsearch.client.*
;
import
javax.annotation.PostConstruct
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
@Slf4j
...
...
@@ -99,20 +100,15 @@ public class ESHelper {
}
public
void
delete
(
String
type
,
String
id
)
{
try
{
DeleteRequest
req
=
new
DeleteRequest
(
esIndex
,
type
+
"_"
+
id
);
DeleteResponse
resp
=
client
.
delete
(
req
,
RequestOptions
.
DEFAULT
);
validStatus
(
resp
.
status
(),
RestStatus
.
OK
);
}
catch
(
IOException
e
)
{
log
.
error
(
"ES Helper error:{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
}
}
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -133,8 +129,6 @@ public class ESHelper {
helper
.
client
=
highClient
;
SearchSourceBuilder
search
=
new
SearchSourceBuilder
();
BoolQueryBuilder
boolQb
=
QueryBuilders
.
boolQuery
();
...
...
@@ -153,23 +147,27 @@ public class ESHelper {
search
.
query
(
boolQb
).
from
(
0
).
size
(
50
);
try
{
DeleteRequest
req1
=
new
DeleteRequest
(
"new-community"
,
"2_88505497717006377"
);
DeleteResponse
resp1
=
helper
.
client
.
delete
(
req1
,
RequestOptions
.
DEFAULT
);
System
.
out
.
println
(
JsonUtil
.
toJson
(
resp1
));
try
{
SearchRequest
req
=
new
SearchRequest
(
"new-community"
);
req
.
source
(
search
);
SearchResponse
resp
=
helper
.
client
.
search
(
req
,
RequestOptions
.
DEFAULT
);
SearchRequest
req
=
new
SearchRequest
(
"new-community"
);
req
.
source
(
search
);
SearchResponse
resp
=
helper
.
client
.
search
(
req
,
RequestOptions
.
DEFAULT
);
SearchHit
[]
hits
=
resp
.
getHits
().
getHits
();
System
.
out
.
println
(
hits
.
length
);
for
(
SearchHit
hit
:
hits
)
{
System
.
out
.
println
(
hit
.
toString
());
System
.
out
.
println
(
hit
.
getFields
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
SearchHit
[]
hits
=
resp
.
getHits
().
getHits
();
System
.
out
.
println
(
hits
.
length
);
for
(
SearchHit
hit
:
hits
)
{
System
.
out
.
println
(
hit
.
toString
());
System
.
out
.
println
(
hit
.
getFields
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"done"
);
System
.
out
.
println
(
"done"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment