不确定如何使用嵌套属性构造ElasticSearch范围查询

时间:2015-11-23 20:24:34

标签: elasticsearch

我在ES中的对象看起来像:

{
  "_index": "myIndex",
  "_type": "myType",
  "_id": "75fd98d2-eca7-4a94-9dd8-1cc2c9b1fbbf",
  "_version": 2,
  "found": true,
  "_source": {
    "account_id": "100",
    "import_ids": [
      "4f4eef42-5493-464e-ac08-68a3a25a01fb"
    ],
    "accept": "html",
    "deleted_at": null,
    "signup_form_ids": [
      {
        "timestamp": "2015-11-23T20:08:11.604000",
        "signup_form_id": "1234"
      }
    ],
    "mailing_status": "active",
    "group_ids": [
      "0eddd2c0-ce70-4eb7-bcd8-9e41e41ac0b3"
    ],
    "confirmed_opt_in_at": null,
    "fields": [
      {
        "text_value": "My Company",
        "name": "company"
      },
      {
        "text_value": "Foo",
        "name": "first-name"
      },
      {
        "text_value": "Bar",
        "name": "last_name"
      },
      {
        "text_value": "555-555-5555",
        "name": "phone"
      }
    ],
    "created_at": "2015-11-23T19:20:15.889000",
    "last_modified_at": "2015-11-23T20:08:11.604000",
    "bounce_count": 0,
    "opted_out_at": null,
    "archived_at": null,
    "email": "example@example.com",
    "opt_out_mailing_id": "None"
  }
}

我正在尝试运行编写一个查询,其中包含signup_form_ids.timestamplte now-7d/d的所有匹配。我正在查看https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#ranges-on-dates,但不确定如何构建查询

这是我到目前为止所做的:

{
    "query": {
        "nested": {
            "path": "signup_form_ids",
            "bool": {
                "must": [
                    {
                        "range": {
                            "timestamp" {
                                "lte": "now-7d/d"
                            }
                        }
                    }
                ]
            }
        },
        "bool": {
            "must": [
                {
                    "bool": {
                        "must": []
                    }
                },
                {
                    "match": {
                        "account_id": "100"
                    }
                },
                {
                    "filtered": {
                        "filter": {
                            "missing": {
                                "field": "deleted_at"
                            }
                        }
                    }
                }
            ]
        }
    },
    "size": 500,
    "from": 0
}

0 个答案:

没有答案