弹性搜索列出与时间范围匹配的条件的所有关键字

时间:2019-05-10 07:30:46

标签: elasticsearch full-text-search key-value elasticsearch-5 full-text-indexing

我必须搜索ES以便在一段时间内符合条件的情况下打印出字段。

尝试以下查询以在过去24小时内匹配一个数字,但没有给出输出

{
    "query": {
        "bool": {
            "must": {
                "match_phrase": {
                    "Number": "1234567"
                }
            },
            "filter": {
                "range": {
                    "@timestamp": {
                        "gte": "now-1d/d"
                    }
                }
            }
        }
    }
}' 

我正在寻找查询以列出过去24小时内的所有数字。有没有办法得到它。

我正在搜索的索引的映射为:

{
  "_index": "data-changes",
  "_type": "_doc",
  "_id": “123456”,
  "_version": 132,
  "_score": 0,
  "_source": {
    "work_notes": "",
    "priority": "4 - Low",
    "planned_start": 1557464400000,
    "Updated_by": "system",
    "Updated": 1557464427000,
    "description": “test of 123456“,
    "phase": "Requested",
    "Number": “123456”,
    "cmdb_ci": "",
    "review_status": "",
    "impact": "No - No impact",
    "phase_state": "Open",
    "Requested_by": “guest”,
    "requested_by_group": “guest_ninja”,
    "Short_description": “ninja rollout“,
    "risk": "Low",
    "actual_end": 0,
    "knowledge_id": "",
    "change_manager_group": “ninja_world_one”,
    "approval": "Approved",
    "downtime": "false",
    "close_notes": "",
    "Standard_template_version": "",
    "User_input": "",
    "ci_class": "Application",
    "category": "Other",
    "created_on": 1557426592000,
    "Created_by": “guest”,
    "Opened_by": “guest”,
    "State": "Implement",
    "availability_impacted": "None expected",
    "planned_end": 1557478800000,
    "close_code": null,
    "actual_start": 1557464427000,
    "closed_by": "",
    "Record_url": “http://localhost:8080”,
    "Type": "Normal"
  },
  "fields": {
    "planned_start": [
      "2019-05-10T05:00:00.000Z"
    ],
    "actual_start": [
      "2019-05-10T05:00:27.000Z"
    ],
    "actual_end": [
      "1970-01-01T00:00:00.000Z"
    ],
    "Updated": [
      "2019-05-10T05:00:27.000Z"
    ],
    "created_on": [
      "2019-05-09T18:29:52.000Z"
    ]
  },

1 个答案:

答案 0 :(得分:0)

您的查询没有返回任何内容,因为您的文档中没有任何@timestamp字段。您需要使用现有的日期字段,例如planned_start

{
    "query": {
        "bool": {
            "must": {
                "match_phrase": {
                    "Number": "1234567"
                }
            },
            "filter": {
                "range": {
                    "planned_start": {
                        "gte": "now-1d/d"
                    }
                }
            }
        }
    }
}'