elasticsearch 历史上的今天

Today in history elasticsearch

我想在今天捕捉历史上的数据。 此查询 returns 为空。我想忽略岁月。

"query": {
    "bool": {
      "filter": [
        {
          "range": {
            "created_at": {
              "gte": "02-15",
              "lte": "02-15",
              "format": "MM-dd"
            }
          }
        }
      ]
    }
  }

https://www.elastic.co/blog/an-introduction-to-elasticsearch-sql-with-practical-examples-part-1 我从文章中得到了帮助。

适合自己here

{
  "query" : {
    "bool" : {
      "must" : [
        {
          "script" : {
            "script" : {
              "source" : "InternalSqlScriptUtils.nullSafeFilter(InternalSqlScriptUtils.eq(InternalSqlScriptUtils.dateTimeChrono(InternalSqlScriptUtils.docValue(doc,params.v0), params.v1, params.v2),params.v3))",
              "lang" : "painless",
              "params" : {
                "v0" : "created_at",
                "v1" : "Z",
                "v2" : "DAY_OF_MONTH",
                "v3" : 15
              }
            }
          }
        },
        {
          "script" : {
            "script" : {
              "source" : "InternalSqlScriptUtils.nullSafeFilter(InternalSqlScriptUtils.eq(InternalSqlScriptUtils.dateTimeChrono(InternalSqlScriptUtils.docValue(doc,params.v0), params.v1, params.v2),params.v3))",
              "lang" : "painless",
              "params" : {
                "v0" : "created_at",
                "v1" : "Z",
                "v2" : "MONTH_OF_YEAR",
                "v3" : 2
              }
            }
          }
        }
      ]
    }
  }
}

我就是这样解决问题的。也许它对其他人有用。