elasticsearch错误

0

错误日志:

[2021-01-11T10:44:40,184][WARN ][o.e.x.m.e.l.LocalExporter] [node-1] unexpected error while indexing monitoring document
org.elasticsearch.xpack.monitoring.exporter.ExportException: org.elasticsearch.common.ValidationException: Validation Failed: 1: this action would add [1] total shards, but this cluster currently has [3693]/[1000] maximum shards open;
	at org.elasticsearch.xpack.monitoring.exporter.local.LocalBulk.lambda$throwExportException$2(LocalBulk.java:125) ~[x-pack-monitoring-7.3.0.jar:7.3.0]
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[?:?]
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) ~[?:?]
	at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[?:?]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[?:?]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[?:?]
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) ~[?:?]

临时修改:

curl -u user:password -XPUT localhost:9200/_cluster/settings -H 'content-Type:application/json' -d '{
  "transient": {
    "cluster": {
      "max_shards_per_node": 6000
    }
  }
}'

永久修改:

curl -u user:password -XPUT localhost:9200/_cluster/settings -H 'content-Type:application/json' -d '{
  "persistent": {
    "cluster": {
      "max_shards_per_node": 6000
    }
  }
}'

read_only_allow_delete

PUT /_setting

{
  "index.blocks.read_only_allow_delete": null
}

枚举索引

我还是喜欢直接使用枚举名称,但是也有部分喜欢使用索引的,记录一下。

    @Bean
	public ElasticsearchConverter elasticsearchEntityMapper(SimpleElasticsearchMappingContext simpleElasticsearchMappingContext) {
		final MappingElasticsearchConverter mappingElasticsearchConverter = new MappingElasticsearchConverter(simpleElasticsearchMappingContext);
		mappingElasticsearchConverter.setConversions(this.elasticsearchCustomConversions());
		return mappingElasticsearchConverter;
	}
	
	@Bean
	public ElasticsearchCustomConversions elasticsearchCustomConversions() {
	    return new ElasticsearchCustomConversions(List.of(
	    	Action.ActionToValueConverter.INSTANCE,
	    	Action.ValueToActionConverter.INSTANCE,
	    	Status.StatusToValueConverter.INSTANCE,
	    	Status.ValueToStatusConverter.INSTANCE,
	    	AlarmLevel.AlarmLevelToValueConverter.INSTANCE,
	    	AlarmLevel.ValueToAlarmLevelConverter.INSTANCE,
	    	AlarmObjType.AlarmObjTypeToValueConverter.INSTANCE,
	    	AlarmObjType.ValueToAlarmObjTypeConverter.INSTANCE
    	));
	}

	@WritingConverter
	public enum ActionToValueConverter implements Converter<Action, Integer> {
		INSTANCE;
		@Override
		public Integer convert(Action source) {
			return source.value;
		}
	}

	@ReadingConverter
	public enum ValueToActionConverter implements Converter<Integer, Action> {
		INSTANCE;
		@Override
		public Action convert(Integer source) {
			for (Action value : Action.values()) {
				if (value.value.equals(source)) {
					return value;
				}
			}
			return null;
		}
	}

more_like_this

min_doc_freq:文档的最小频率,低于该频率的输入文档应被忽略。默认值为5。
max_doc_freq:最大文档频率,高于该频率时,输入文档的术语应被忽略。忽略非常频繁的术语(如停用词)会很有用。默认情况下它被禁用0。
min_term_freq:应忽略输入文档/文本中的术语的最小频率。默认值为2。
min_word_length:最小术语长度,低于该长度的术语应被忽略。默认值为0。
max_word_length:最大术语大小,超过该术语应被忽略。默认情况下它被禁用0。
max_query_terms:要选择的最大术语数。拥有的术语越多,准确度就越高,但以牺牲性能为代价。默认值为25。
stop_words:一组停用词,要忽略的术语。

{"query":{"more_like_this":{"fields":["content"],"like":[{"_id":"4"}],"min_doc_freq":2,"max_doc_freq":100,"min_term_freq":0,"max_query_terms":12}}}

这里需要注意一下上面的min参数配置,测试的时候词频可能不够,导致查询没有数据。