Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7c66b1b2
authored
Jun 09, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
es请求
parent
460cb341
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
5 deletions
conf/config.ini
pkg/es/es.go
readme.md
test/test.go
conf/config.ini
View file @
7c66b1b2
...
...
@@ -11,7 +11,7 @@ api_url = http://192.168.2.232:60004
[es]
url
=
http://192.168.2.232:9200
urls
=
http://192.168.2.232:9200,http://192.168.2.232:9200
index_name
=
future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,
peigenesis,powell,rs,buerklin
index_name
=
future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,
zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
[database]
user_name
=
root
...
...
pkg/es/es.go
View file @
7c66b1b2
...
...
@@ -5,12 +5,26 @@ import (
"search_server/pkg/config"
)
func
CurlEs
(
param
string
)
{
goodsServerUrl
:=
config
.
Get
(
"es.api_url"
)
.
String
()
type
Response
struct
{
Took
int
`json:"took"`
TimeOut
bool
`json:"time_out"`
Shard
map
[
string
]
int
`json:"_shard"`
HitsResult
HitsResult
`json:"hits"`
}
type
HitsResult
struct
{
Total
int
`json:"total"`
MaxScore
float64
`json:"max_score"`
Hits
string
`json:"hits"`
}
func
CurlES
(
index
string
,
param
string
)
(
err
error
,
result
string
)
{
goodsServerUrl
:=
config
.
Get
(
"es.url"
)
.
String
()
params
:=
req
.
BodyJSON
(
param
)
resp
,
err
:=
req
.
Post
(
goodsServerUrl
+
"/synchronization
"
,
params
)
resp
,
err
:=
req
.
Get
(
goodsServerUrl
+
"/"
+
index
+
"/_search
"
,
params
)
if
err
!=
nil
{
return
}
return
resp
.
String
()
result
=
resp
.
String
()
return
}
readme.md
View file @
7c66b1b2
...
...
@@ -46,3 +46,6 @@ mgo包的文档 : https://godoc.org/gopkg.in/mgo.v2
#### 6.商品信息获取
直接调用
```service.GetGoodsInfo```
函数即可,传入goods_id的字符串,多个goods_id用逗号隔开(商品服务的请求本来亦是如此),会返回json字符串,然后可以根据自己的需求用gjson获取对应的信息即可
#### 7.ES的基本请求
直接调用
```es.CurlES```
函数即可,传入索引名称和请求的json参数即可,得到的返回结果是ES的原生结果,可以根据自己的需求用gjson获取对应的信息
test/test.go
View file @
7c66b1b2
...
...
@@ -2,8 +2,11 @@ package main
import
(
"flag"
"fmt"
"log"
"search_server/boot"
"search_server/pkg/config"
"search_server/pkg/es"
)
func
main
()
{
...
...
@@ -13,4 +16,31 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
log
.
Println
(
err
)
}
fmt
.
Println
(
es
.
CurlES
(
config
.
Get
(
"es.index_name"
)
.
String
(),
`{
"query": {
"bool": {
"filter": [
{
"term": {
"goods_id": "1154020374326836400"
}
}
]
}
},
"sort": [
{
"single_price": {
"order": "asc"
}
},
{
"_score": {
"order": "desc"
}
}
],
"from": 0,
"size": 10
}`
))
}
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