[英]Elasticsearch. Search data by current month
I have next body我有下一个身体
body = {
"size": 100,
"query": {
"bool": {
"filter": [
{
"term": {
"some_id_1": some_id_1
}
},
{
"term": {
"some_id_2": some_id_2
}
},
{
"term": {
"some_id_2": some_id_2
}
},
{
"terms": {
"some_strings": "a,b,c"
}
},
{
"term": {
"created_at": dt.now().strftime("%Y-%m-%d")
}
}
]
}
}
}
This will search all record by condition in term for dt.now().这将按条件搜索 dt.now() 的所有记录。
Question: How i can search all documents for current month?问题:如何搜索当月的所有文档?
Will be grateful for the help.将不胜感激的帮助。
You can use a range
query instead with some date math , like this:您可以使用range
查询代替某些日期数学,如下所示:
{
"range": {
"created_at": {
"gte": "now/M"
}
}
}
All documents whose created_at
field is on the first day of this month or later will be returned.将返回所有created_at
字段在本月第一天或之后的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.