You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package EsUtil
import (
"dsData/Utils/ConfigUtil"
"dsData/Utils/HttpUtil"
"fmt"
"github.com/tidwall/gjson"
)
/**
功能:对指定的索引进行分页查询
作者:黄海
时间: 2020-03-23
*/
func QueryPage ( indexName string , lastUpdatedTime string , pk string ) ( string , string , [ ] map [ string ] interface { } ) {
url := ConfigUtil . ElasticSearchAddress + "/" + indexName + "/_search?pretty"
postBody := `
{
"track_total_hits":true,
"query": {
"bool": {
"must": [ {
"range": {
"last_updated_time": {
"gte": " ` + lastUpdatedTime + ` "
}
}
},
{
"range": {
"pk": {
"gt": " ` + pk + ` "
}
}
}]
}
},
"sort": [
{
"last_updated_time": { "order": "asc"}
},
{
"pk": { "order": "asc"}
}
],
"from": 0,
"size": 100
}
`
body , err := HttpUtil . FastHttpPost ( url , postBody )
if err != nil {
fmt . Println ( err )
}
//万能的map[string]interface{}
var list [ ] map [ string ] interface { }
var vLastUpdatedTime string
var vPk string
gjson . Get ( body , "hits" ) . Get ( "hits" ) . ForEach ( func ( key , value gjson . Result ) bool {
//反序列化到map
result , _ := value . Get ( "_source" ) . Value ( ) . ( map [ string ] interface { } )
list = append ( list , result )
//记录最后一条的最后修改时间,最后一条的主键
vLastUpdatedTime = value . Get ( "last_updated_time" ) . String ( )
vPk = value . Get ( "pk" ) . String ( )
return true // 保持继续!
} )
return vLastUpdatedTime , vPk , list
}