如何创建允许弹性搜索中的动态索引别名的模板

时间:2017-05-30 22:29:40

标签: elasticsearch

我正在尝试使用elasticsearch 2.4跟随此doc,其中多个租户数据可以放入一个索引但是通过使用别名和路由,我可以搜索别名索引,只检索来自一个特定租户的信息。 / p>

简单地说,我可以在索引 search_widgets 下填充一个小部件文档类型的索引。但是当我根据user-id的值输入widget文件时,模板会创建一个别名。如果窗口小部件类型doc具有user-id = 1,则它将创建索引别名search_widget-1。如果在该索引上使用get-all进行搜索,则会返回包含user-id = 1作为其中字段的小部件文档。

这是一个不完整的例子,说明它应该如何运作

PUT / search_widgets

{
  "search_widgets": {
    "settings": {
      "number_of_shards": 2
    },
    "mappings": {
      "widget": {
        "properties": {
          "@timestamp": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          },
          "@version": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "user-id": {
            "type": "number",
            "index": "not_analyzed"
          },
          "created_date": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          },
          "name": {
            "type": "string"
          },
          "updated_date": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          },
          "id": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    },
    "aliases": {
      "widget": {
        "routing": "search_widget_*",
        "filter": {
          "term": {
            "user-id": "*"
          }
        }
      }
    }
  }
}

0 个答案:

没有答案