2016-07-26 92 views
0

是否可以创建索引,限制索引父属性?ElasticSearch创建具有动态属性的索引

例如,

$ curl -XPOST 'http://localhost:9200/actions/action/' -d '{ 
    "user": "kimchy", 
    "message": "trying out Elasticsearch", 
    "actionHistory": [ 
    { "timestamp": 123456789, "action": "foo" }, 
    { "timestamp": 123456790, "action": "bar" }, 
    { "timestamp": 123456791, "action": "buz" }, 
    ... 
    ] 
}' 

我不想actionHistory在所有索引。如何才能做到这一点?

对于上述文件,我相信该指数将作为

$ curl -XPOST localhost:9200/actions -d '{ 
    "settings": { 
    "number_of_shards": 1 
    }, 
    "mappings": { 
    "action": { 
     "properties" : { 
     "user": { "type": "string", "index" : "analyzed" }, 
     "message": { "type": "string": "index": "analyzed" }, 
     "actionHistory": { 
      "properties": { 
      "timestamp": { 
       "type": "date", 
       "format": "strict_date_optional_time||epoch_millis" 
      }, 
      "action": { "type": "string", "index": "analyzed" } 
      } 
     } 
     } 
    } 
    } 
}' 

会去除actionHistoryproperties"index": "no"替换它是妥善解决产生的呢?

这是一个例子,但是我的实际情况是具有动态属性的文档(即actionHistory包含各种自定义的,非重复的属性),我的这个特定类型的映射定义有超过2000个不同的属性,慢(即比数据库中的全文搜索最差)。

+0

嗯,你的搜索查询是如何构建的,因为'actionHistory'如此不同使得它们表现不佳?你在搜索或字段名称通配符中使用了'_all'吗? –

+0

是的,我让用户使用'query_string'形式。 –

+0

这就是允许用户用'query_string'完成他们想做的任何事情的缺点。同样,允许用户在所有文档中创建_various自定义非重复属性。您可以从这些任意的query_strings中获得各种问题,并在文档中拥有任何属性。我建议限制这些自由以获得更稳定和可预测的群集。 –

回答

1

您可能可以通过使用dynamic templates,匹配所有actionHistory子字段并将"index": "no"设置为全部匹配。

PUT actions 
{ 
    "mappings": { 
    "action": { 
     "dynamic_templates": [ 
     { 
      "actionHistoryRule": { 
      "path_match": "actionHistory.*", 
      "mapping": { 
       "type": "{dynamic_type}", 
       "index": "no" 
      } 
      } 
     } 
     ] 
    } 
    } 
} 
+0

这是什么运气? – Val