-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Youssef Aouichaoui <[email protected]>
- Loading branch information
1 parent
f198fb4
commit 5a582ac
Showing
5 changed files
with
286 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
src/main/java/org/springframework/data/elasticsearch/core/mapping/DynamicTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
package org.springframework.data.elasticsearch.core.mapping; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Immutable Value object encapsulating dynamic template(s). | ||
* {@see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html">Elastic | ||
* docs</a>} | ||
* | ||
* @author Youssef Aouichaoui | ||
* @since 5.4 | ||
*/ | ||
public class DynamicTemplate { | ||
/** | ||
* Patterns to match on the field name. | ||
*/ | ||
private final List<String> match; | ||
|
||
/** | ||
* Path patterns for a nested type to match the field name. | ||
*/ | ||
private final List<String> pathMatch; | ||
|
||
/** | ||
* Patterns that do not match the field name. | ||
*/ | ||
private final List<String> unmatch; | ||
|
||
/** | ||
* Path patterns for a nested type that do not match the field name. | ||
*/ | ||
private final List<String> pathUnmatch; | ||
|
||
/** | ||
* Data types that correspond to the field. | ||
*/ | ||
private final List<String> matchMappingType; | ||
|
||
/** | ||
* Data types that do not match to the field. | ||
*/ | ||
private final List<String> unmatchMappingType; | ||
|
||
private DynamicTemplate(Builder builder) { | ||
this.match = builder.match; | ||
this.pathMatch = builder.pathMatch; | ||
|
||
this.unmatch = builder.unmatch; | ||
this.pathUnmatch = builder.pathUnmatch; | ||
|
||
this.matchMappingType = builder.matchMappingType; | ||
this.unmatchMappingType = builder.unmatchMappingType; | ||
} | ||
|
||
public List<String> getMatch() { | ||
return match; | ||
} | ||
|
||
public List<String> getPathMatch() { | ||
return pathMatch; | ||
} | ||
|
||
public List<String> getUnmatch() { | ||
return unmatch; | ||
} | ||
|
||
public List<String> getPathUnmatch() { | ||
return pathUnmatch; | ||
} | ||
|
||
public List<String> getMatchMappingType() { | ||
return matchMappingType; | ||
} | ||
|
||
public List<String> getUnmatchMappingType() { | ||
return unmatchMappingType; | ||
} | ||
|
||
public boolean isRegexMatching() { | ||
return false; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
private final List<String> match = new ArrayList<>(); | ||
private final List<String> pathMatch = new ArrayList<>(); | ||
|
||
private final List<String> unmatch = new ArrayList<>(); | ||
private final List<String> pathUnmatch = new ArrayList<>(); | ||
|
||
private final List<String> matchMappingType = new ArrayList<>(); | ||
private final List<String> unmatchMappingType = new ArrayList<>(); | ||
|
||
private Builder() {} | ||
|
||
/** | ||
* Patterns to match on the field name. | ||
*/ | ||
public Builder withMatch(String... match) { | ||
for (String value : match) { | ||
if (value != null) { | ||
parseValues(value, this.match); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Path patterns for a nested type to match the field name. | ||
*/ | ||
public Builder withPathMatch(String... pathMatch) { | ||
for (String value : pathMatch) { | ||
if (value != null) { | ||
parseValues(value, this.pathMatch); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Patterns that do not match the field name. | ||
*/ | ||
public Builder withUnmatch(String... unmatch) { | ||
for (String value : unmatch) { | ||
if (value != null) { | ||
parseValues(value, this.unmatch); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Path patterns for a nested type that do not match the field name. | ||
*/ | ||
public Builder withPathUnmatch(String... pathUnmatch) { | ||
for (String value : pathUnmatch) { | ||
if (value != null) { | ||
parseValues(value, this.pathUnmatch); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Data types that correspond to the field. | ||
*/ | ||
public Builder withMatchMappingType(String... matchMappingType) { | ||
for (String value : matchMappingType) { | ||
if (value != null) { | ||
parseValues(value, this.matchMappingType); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Data types that do not match to the field. | ||
*/ | ||
public Builder withUnmatchMappingType(String... unmatchMappingType) { | ||
for (String value : unmatchMappingType) { | ||
if (value != null) { | ||
parseValues(value, this.unmatchMappingType); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
private void parseValues(String source, List<String> target) { | ||
if (source.startsWith("[")) { | ||
target.addAll(List.of(source.replace("[", "").replace("]", "").split(",", -1))); | ||
} else { | ||
target.add(source); | ||
} | ||
} | ||
|
||
public DynamicTemplate build() { | ||
return new DynamicTemplate(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.