地理、日期和字符串匹配 elasticsearch 查询
Geo, Date, and string matching elasticsearch query
我有一个名为 tweets 的 elasticsearch 索引,
我正在尝试按 geo_distance、日期和可能传递的可选字符串来过滤这些推文。这个查询应该怎么样才能满足我的要求
"query":{
"bool": {
"must": [
{
"term": {
"text": "ew"
}
},
{
"range": {
"date": {
"gte": "2009-05-31T02:30:45",
"lt": "now"
}
}
},
{
"filter": {
"geo_distance": {
"distance": "12km",
"pin.location": [-70, 40]
}
}
}
]
}
}
提前致谢
您可以使用 filter
and should
clause 的组合来达到您需要的结果。
filter
类似于逻辑AND运算符,忽略查询的分数,should
类似于逻辑OR运算符。
试试下面的查询:
{
"query": {
"bool": {
"filter": [
{
"range": {
"date": {
"gte": "2009-05-31T02:30:45",
"lt": "now"
}
}
},
{
"geo_distance": {
"distance": "12km",
"pin.location": [
-70,
40
]
}
}
],
"should": {
"bool": {
"filter": {
"term": {
"text": "ew"
}
}
}
}
}
}
}
我有一个名为 tweets 的 elasticsearch 索引, 我正在尝试按 geo_distance、日期和可能传递的可选字符串来过滤这些推文。这个查询应该怎么样才能满足我的要求
"query":{
"bool": {
"must": [
{
"term": {
"text": "ew"
}
},
{
"range": {
"date": {
"gte": "2009-05-31T02:30:45",
"lt": "now"
}
}
},
{
"filter": {
"geo_distance": {
"distance": "12km",
"pin.location": [-70, 40]
}
}
}
]
}
}
提前致谢
您可以使用 filter
and should
clause 的组合来达到您需要的结果。
filter
类似于逻辑AND运算符,忽略查询的分数,should
类似于逻辑OR运算符。
试试下面的查询:
{
"query": {
"bool": {
"filter": [
{
"range": {
"date": {
"gte": "2009-05-31T02:30:45",
"lt": "now"
}
}
},
{
"geo_distance": {
"distance": "12km",
"pin.location": [
-70,
40
]
}
}
],
"should": {
"bool": {
"filter": {
"term": {
"text": "ew"
}
}
}
}
}
}
}