spring-data-elasticsearch RuntimeField 源码

  • 2022-08-16
  • 浏览 (282)

spring-data-elasticsearch RuntimeField 代码

文件路径:/src/main/java/org/springframework/data/elasticsearch/core/RuntimeField.java

/*
 * Copyright 2021-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.data.elasticsearch.core;

import java.util.HashMap;
import java.util.Map;

import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
 * Defines a runtime field to be added to a Query
 *
 * @author Peter-Josef Meisch
 * @author cdalxndr
 * @since 4.3
 */
public class RuntimeField {

	private final String name;
	private final String type;
	@Nullable private final String script;

	public RuntimeField(String name, String type) {
		this(name, type, null);
	}

	public RuntimeField(String name, String type, @Nullable String script) {

		Assert.notNull(name, "name must not be null");
		Assert.notNull(type, "type must not be null");

		this.name = name;
		this.type = type;
		this.script = script;
	}

	public String getName() {
		return name;
	}

	/**
	 * @return the mapping as a Map like it is needed for the Elasticsearch client
	 */
	public Map<String, Object> getMapping() {
		Map<String, Object> map = new HashMap<>();
		map.put("type", type);

		if (script != null) {
			map.put("script", script);
		}
		return map;
	}

	/**
	 * @since 4.4
	 */
	public String getType() {
		return type;
	}

	/**
	 * @since 4.4
	 */
	public @Nullable String getScript() {
		return script;
	}
}

相关信息

spring-data-elasticsearch 源码目录

相关文章

spring-data-elasticsearch AbstractElasticsearchTemplate 源码

spring-data-elasticsearch AbstractIndexTemplate 源码

spring-data-elasticsearch AbstractReactiveElasticsearchTemplate 源码

spring-data-elasticsearch ActiveShardCount 源码

spring-data-elasticsearch AggregationContainer 源码

spring-data-elasticsearch AggregationsContainer 源码

spring-data-elasticsearch DocumentOperations 源码

spring-data-elasticsearch ElasticsearchOperations 源码

spring-data-elasticsearch EntityOperations 源码

spring-data-elasticsearch IndexInformation 源码

0  赞