将索引配置应用于索引创建

时间:2020-09-11 07:54:31

标签: elasticsearch hibernate-search

我正在使用hibernate-search-elasticsearch 5.11.5,我遇到了一个索引限制-总字段限制,默认为1000。我需要增加此限制,不幸的是,这是一个索引限制,这意味着它必须为在创建索引之后设置。因为我有1000多个字段, 创建映射时发生错误。问题在于创建索引映射的请求是在创建索引之后执行的,我看不到在创建映射之前应用索引设置的方法。这是来自ElasticsearchIndexManager类的用于处理索引和映射创建的代码:

 case DROP_AND_CREATE:
 case DROP_AND_CREATE_AND_DROP:
        ElasticsearchSchemaDropper schemaDropper = elasticsearchService.getSchemaDropper();
            schemaDropper.dropIfExisting( actualIndexName, schemaManagementExecutionOptions );
            schemaCreator.createIndex( indexMetadata, schemaManagementExecutionOptions );
            schemaCreator.createMappings( indexMetadata, schemaManagementExecutionOptions );
            createdIndex = true;
            break;

在创建索引后是否有可能应用索引设置。如果不是的话,除了减少字段之外,您还有什么建议(我知道这么多字段有什么风险)?

1 个答案:

答案 0 :(得分:1)

您应该事先创建索引模板:在创建索引之前定义具有适当设置的模板,并且当Hibernate Search创建索引时,Elasticsearch将自动应用这些设置。

请参见https://www.elastic.co/guide/en/elasticsearch/reference/5.6/indices-templates.html

注意,Hibernate Search 5仍会在启动时创建索引,因此,例如,您需要在启动应用程序之前通过使用Shell脚本和curl自己向集群发送REST请求来创建这些模板。