Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
api
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
bigdata
api
Commits
5bc91bff
Commit
5bc91bff
authored
May 31, 2021
by
杨林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
搜索es方法
parent
c02cdaf9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
src/main/Python/estools.py
src/main/Python/estools.py
+19
-1
No files found.
src/main/Python/estools.py
View file @
5bc91bff
...
...
@@ -5,9 +5,13 @@ class ESTools:
"""
es工具
"""
# es库
_index
=
'goods'
# es主机
_host
=
[{
"host"
:
'172.18.45.18'
,
"port"
:
9200
},
{
"host"
:
'172.18.45.17'
,
"port"
:
9200
},
{
"host"
:
'172.18.45.16'
,
"port"
:
9200
},
{
"host"
:
'172.18.69.190'
,
"port"
:
9200
}]
{
"host"
:
'172.18.45.16'
,
"port"
:
9200
},
{
"host"
:
'172.18.69.190'
,
"port"
:
9200
},
{
"host"
:
'172.18.69.192'
,
"port"
:
9200
}]
_TB_RATE
=
0.7
_JD_RATE
=
0.55
...
...
@@ -23,6 +27,7 @@ class ESTools:
:return: 搜索结果和分数
"""
if
self
.
es
.
ping
():
# es查询语句
query
=
{
"query"
:
{
"bool"
:
{
...
...
@@ -43,8 +48,10 @@ class ESTools:
"from"
:
0
,
"size"
:
size
}
# 查询结果
hits
=
self
.
es
.
search
(
index
=
self
.
_index
,
body
=
query
)
res
=
hits
[
'hits'
][
'hits'
]
# 取出查询分数
scores
=
[
i
[
'_score'
]
for
i
in
res
]
scores
=
sorted
(
scores
)
return
res
,
scores
...
...
@@ -68,17 +75,27 @@ class ESTools:
score_median
=
sco
[
int
(
len
(
sco
)
/
2
)]
for
i
in
res
:
# 对每条数据进行处理
# 分数大于中位数
if
i
[
"_score"
]
>
score_median
:
# 分数大于平均数
if
i
[
"_score"
]
>
score_avg
:
# 源数据
source
=
i
[
'_source'
]
# 平台
platform
=
source
[
"platform"
]
# 券后佣金
coupon_commission
=
source
[
"coupon_commission"
]
# 给用户的佣金比例
rate
=
self
.
_JD_RATE
if
platform
==
2
else
self
.
_TB_RATE
# 券金额
coupon_amount
=
source
[
"coupon_amount"
]
# 优惠文案
discount_text
=
f'¥
{
coupon_amount
}
券'
if
coupon_amount
>
0
else
''
# 用户佣金
user_commission
=
"{:.2f}"
.
format
(
coupon_commission
*
rate
)
# 券后价
end_price
=
source
[
"coupon_price"
]
# 最终优惠金额
final_price
=
round
(
price
-
end_price
,
2
)
result
=
{
"item_id"
:
source
[
"item_id"
],
...
...
@@ -97,6 +114,7 @@ class ESTools:
"user_commission_text"
:
f'返现
{
user_commission
}
'
}
temp
.
append
(
result
)
# 按价格排序
results
=
sorted
(
temp
,
key
=
lambda
x
:
x
[
"end_price"
])
return
results
else
:
...
...
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