Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
3ff97718
Commit
3ff97718
authored
Aug 21, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
es随机查询
parent
8bd2d285
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
10 deletions
+9
-10
ch-dao/pom.xml
ch-dao/pom.xml
+2
-1
ch-dao/src/main/java/com/wwdz/ch/db/es/ItemEsDao.java
ch-dao/src/main/java/com/wwdz/ch/db/es/ItemEsDao.java
+7
-9
No files found.
ch-dao/pom.xml
View file @
3ff97718
...
@@ -110,10 +110,11 @@
...
@@ -110,10 +110,11 @@
<version>
1.2.12
</version>
<version>
1.2.12
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
co.elastic.clients
</groupId>
<groupId>
co.elastic.clients
</groupId>
<artifactId>
elasticsearch-java
</artifactId>
<artifactId>
elasticsearch-java
</artifactId>
<version>
8.
8.2
</version>
<version>
8.
9.0
</version>
</dependency>
</dependency>
</dependencies>
</dependencies>
...
...
ch-dao/src/main/java/com/wwdz/ch/db/es/ItemEsDao.java
View file @
3ff97718
...
@@ -6,6 +6,7 @@ import co.elastic.clients.elasticsearch.core.*;
...
@@ -6,6 +6,7 @@ import co.elastic.clients.elasticsearch.core.*;
import
co.elastic.clients.elasticsearch.core.bulk.BulkOperation
;
import
co.elastic.clients.elasticsearch.core.bulk.BulkOperation
;
import
co.elastic.clients.elasticsearch.core.bulk.CreateOperation
;
import
co.elastic.clients.elasticsearch.core.bulk.CreateOperation
;
import
co.elastic.clients.elasticsearch.core.search.Hit
;
import
co.elastic.clients.elasticsearch.core.search.Hit
;
import
co.elastic.clients.elasticsearch.core.search.ScoreMode
;
import
com.wwdz.ch.db.bean.EsPageInfo
;
import
com.wwdz.ch.db.bean.EsPageInfo
;
import
com.wwdz.ch.db.bean.ItemOfEs
;
import
com.wwdz.ch.db.bean.ItemOfEs
;
import
com.wwdz.ch.db.domain.Item
;
import
com.wwdz.ch.db.domain.Item
;
...
@@ -103,18 +104,15 @@ public class ItemEsDao {
...
@@ -103,18 +104,15 @@ public class ItemEsDao {
build
.
must
(
matchQuery
);
build
.
must
(
matchQuery
);
builder
.
from
(
from
);
builder
.
from
(
from
);
builder
.
query
(
build
.
build
().
_toQuery
());
}
else
{
}
else
{
int
num
=
10000
-
size
;
Random
random
=
new
Random
()
;
Random
random
=
new
Random
();
FunctionScoreQuery
functionScoreQuery
=
FunctionScoreQuery
.
of
(
a
->
a
.
query
(
build
.
build
().
_toQuery
()).
boostMode
(
FunctionBoostMode
.
Replace
)
from
=
random
.
nextInt
(
num
);
.
functions
(
b
->
b
.
randomScore
(
s
->
s
.
field
(
"id"
).
seed
(
String
.
valueOf
(
random
.
nextDouble
()))))
);
builder
.
from
(
from
);
builder
.
query
(
functionScoreQuery
.
_toQuery
()
);
}
}
builder
.
query
(
build
.
build
().
_toQuery
());
builder
.
size
(
size
);
builder
.
size
(
size
);
/* builder.sort(f -> f.field(o -> o.field("coin_id")
.order(SortOrder.Desc)));*/
SearchRequest
searchRequest
=
builder
.
build
();
SearchRequest
searchRequest
=
builder
.
build
();
logger
.
info
(
"查询语句 : {}"
,
searchRequest
.
query
());
logger
.
info
(
"查询语句 : {}"
,
searchRequest
.
query
());
SearchResponse
<
ItemOfEs
>
searchResponse
=
elasticsearchClient
.
search
(
searchRequest
,
ItemOfEs
.
class
);
SearchResponse
<
ItemOfEs
>
searchResponse
=
elasticsearchClient
.
search
(
searchRequest
,
ItemOfEs
.
class
);
long
total
=
searchResponse
.
hits
().
total
().
value
();
long
total
=
searchResponse
.
hits
().
total
().
value
();
...
@@ -127,7 +125,7 @@ public class ItemEsDao {
...
@@ -127,7 +125,7 @@ public class ItemEsDao {
list
.
add
(
itemOfEs
);
list
.
add
(
itemOfEs
);
idList
.
add
(
itemOfEs
.
getId
());
idList
.
add
(
itemOfEs
.
getId
());
}
}
logger
.
info
(
"========
随机
返回的数据id : {}"
,
idList
);
logger
.
info
(
"======== 返回的数据id : {}"
,
idList
);
esPageInfo
=
EsPageInfo
.
of
(
total
,
list
,
page
,
size
);
esPageInfo
=
EsPageInfo
.
of
(
total
,
list
,
page
,
size
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"ES 查询商品列表 error : {}"
,
e
);
logger
.
error
(
"ES 查询商品列表 error : {}"
,
e
);
...
...
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