
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
github.com/KingSolvewer/elasticsearch-query-builder
go get github.com/KingSolvewer/elasticsearch-query-builder
elastic.Where...
...
// 重置后继续使用
elastic.Reset()
elastic.Where...
builer := elastic.NewBuilder()
builer.Where...
builer.Reset().Where
import (
elastic "github.com/KingSolvewer/elasticsearch-query-builder"
)
elastic.Where("status", 1).Where("title", "中国").OrWhere("status", 1).WhereNot("country", "日本").Filter("city", "合肥")
DSL:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"status": 1
}
},
{
"term": {
"title": "中国"
}
}
],
"must_not": [
{
"term": {
"country": "日本"
}
}
],
"should": [
{
"term": {
"status": 1
}
}
],
"filter": [
{
"term": {
"city": "合肥"
}
}
]
}
}
}
import (
elastic "github.com/KingSolvewer/elasticsearch-query-builder"
)
elastic.Where("title", "中国").WhereNested(func(b *elastic.Builder) *elastic.Builder {
return b.OrWhere("title", "美国").OrWhere("title", "日本")
})
DSL:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"title": "中国"
}
},
{
"bool": {
"should": [
{
"term": {
"title": "美国"
}
},
{
"term": {
"title": "日本"
}
}
]
}
}
]
}
}
}
elastic.Select("title", "content")
elastic.AppendField("post_time", "author")
elastic.From(0)
elastic.Size(0)
esearch.Asc
esearch.Desc
elastic.OrderBy("post_time", esearch.Desc)
elastic.Raw(`{"query":{"bool":{"must":[{"term":{"news_uuid":"*********"}}]}}}`)
elastic.Where("post_time", "2024-11-01 00:00:23")
elastic.WherePrefix("username", "ki")
elastic.WhereExists("username")
elastic.WhereRegexp("username", "ki.*y", nil)
elastic.WhereRegexp("username", "ki.*y", func() termlevel.RegexpParam {
return termlevel.RegexpParam{}
})
elastic.WhereWildcard("username", "ki*y", nil)
elastic.WhereWildcard("username", "ki*y", func() termlevel.WildcardParam {
return termlevel.WildcardParam{}
})
any 只允许 go的基础类型 int, uint, int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64, string, bool
elastic.WhereIn("news_emotion", elastic.SliceToAny([]string{"中性", ""})
any 只允许 go的基础类型 int, uint, int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64, string, bool
elastic.WhereBetween("publish_time", "2024-11-01 00:00:00", "2024-12-01 00:00:00")
any 只允许 go的基础类型 int, uint, int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64, string, bool
esearch.Gte
esearch.Gt
esearch.Lt
esearch.Lte
elastic.WhereRange("age", 18, esearch.Gt)
esearch.BestFields
esearch.MostFields
esearch.CrossFields
esearch.Phrase
esearch.PhrasePrefix
esearch.BoolPrefix
elastic.WhereMatch("title", "中国电信", esearch.MatchPhrasePrefix, nil)
elastic.WhereMatch("title", "中国电信", esearch.MatchPhrasePrefix, func() fulltext.AppendParams {
return fulltext.AppendParams{}
})
esearch.Match,esearch.MatchPhrase,esearch.MatchPhrasePrefix
elastic.WhereMultiMatch([]string{"title", "content"}, "中国电信", esearch.BestFields, nil)
elastic.WhereMultiMatch([]string{"title", "content"}, "中国电信", esearch.BestFields, func() fulltext.AppendParams {
return fulltext.AppendParams{}
})
elastic.WhereNested(func(b *elastic.Builder) {
b.Where().WhereIn().OrWhere().WhereNot().Filter()...
})
elastic.Scroll("2m")
elastic.GetScroll()
elastic.ScrollId("**************")
elastic.GetScrollId()
elastic.Collapse("simhash")
elastic.GetScrollId()
elastic.Dsl()
elastic.Marshal()
elastic.GetQuery()
elastic.Clone()
elastic.Reset()
名称 | ES语法 | 方法 | 参数 | 说明 |
---|---|---|---|---|
分组聚合 | terms | elastic.GroupBy() | aggs.TermsParam{} | 对某个字段进行分组聚合 |
直方图聚合 | histogram | elastic.Histogram() | aggs.HistogramParam{} | |
日期直方图聚合 | date_histogram | elastic.DateGroupBy() | aggs.HistogramParam{} | 严格遵照日期直方图聚合的写法 |
数值范围聚合 | range | elastic.Range() | aggs.RangeParam{} | 必须是数值类型的数据 |
日期范围聚合 | date_range | elastic.DateRange() | aggs.RangeParam{} | 严格遵照日期范围聚合的写法 |
名称 | ES语法 | 方法 | 参数 | 说明 |
---|---|---|---|---|
平均数计算 | avg | elastic.Avg() | aggs.MetricParam | |
最大值计算 | max | elastic.Mx() | aggs.MetricParam | |
最小值计算 | min | elastic.Min() | aggs.MetricParam | |
总和计算 | sum | elastic.Sum() | aggs.MetricParam | |
数量计算 | value_count | elastic.ValueCount() | 无 | 类似于 total |
统计 | stats | elastic.Stats() | aggs.MetricParam | |
扩展统计 | extended_stats | elastic.ExtendedStats() | aggs.CardinalityParam | |
分组聚合的数据 | top_hits | elastic.TopHits() | aggs.TopHitsParam | |
分组聚合的数据 | top_hits | elastic.TopHitsFunc() | 闭包函数 | 支持 b.From(0).Size(10).Select().Sort() |
elastic.SliceToAny([]string{"a", "b", "c"})
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.