-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add analysis modes to restrict token filter use contexts (#36103)
Currently token filter settings are treated as fixed once they are declared and used in an analyzer. This is done to prevent changes in analyzers that are already used actively to index documents, since changes to the analysis chain could corrupt the index. However, it would be safe to allow updates to token filters at search time ("search_analyzer"). This change introduces a new property of token filters that allows to mark them as only being usable at search or at index time. Any analyzer that uses these tokenfilters inherits that property and can be rejected if they are used in other contexts. This is a first step towards making specific token filters (e.g. synonym filter) updateable. Relates to #29051
- Loading branch information
Christoph Büscher
authored
Mar 12, 2019
1 parent
6c6c44e
commit ef18d3f
Showing
9 changed files
with
445 additions
and
4 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
server/src/main/java/org/elasticsearch/index/analysis/AnalysisMode.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,82 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you 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 | ||
* | ||
* http://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.elasticsearch.index.analysis; | ||
|
||
/** | ||
* Enum representing the mode in which token filters and analyzers are allowed to operate. | ||
* While most token filters are allowed both in index and search time analyzers, some are | ||
* restricted to be used only at index time, others at search time. | ||
*/ | ||
public enum AnalysisMode { | ||
|
||
/** | ||
* AnalysisMode representing analysis components that can be used only at index time | ||
*/ | ||
INDEX_TIME("index time") { | ||
@Override | ||
public AnalysisMode merge(AnalysisMode other) { | ||
if (other == AnalysisMode.SEARCH_TIME) { | ||
throw new IllegalStateException("Cannot merge SEARCH_TIME and INDEX_TIME analysis mode."); | ||
} | ||
return AnalysisMode.INDEX_TIME; | ||
} | ||
}, | ||
/** | ||
* AnalysisMode representing analysis components that can be used only at search time | ||
*/ | ||
SEARCH_TIME("search time") { | ||
@Override | ||
public AnalysisMode merge(AnalysisMode other) { | ||
if (other == AnalysisMode.INDEX_TIME) { | ||
throw new IllegalStateException("Cannot merge SEARCH_TIME and INDEX_TIME analysis mode."); | ||
} | ||
return AnalysisMode.SEARCH_TIME; | ||
} | ||
}, | ||
/** | ||
* AnalysisMode representing analysis components that can be used both at index and search time | ||
*/ | ||
ALL("all") { | ||
@Override | ||
public AnalysisMode merge(AnalysisMode other) { | ||
return other; | ||
} | ||
}; | ||
|
||
private String readableName; | ||
|
||
AnalysisMode(String name) { | ||
this.readableName = name; | ||
} | ||
|
||
public String getReadableName() { | ||
return this.readableName; | ||
} | ||
|
||
/** | ||
* Returns a mode that is compatible with both this mode and the other mode, that is: | ||
* <ul> | ||
* <li>ALL.merge(INDEX_TIME) == INDEX_TIME</li> | ||
* <li>ALL.merge(SEARCH_TIME) == SEARCH_TIME</li> | ||
* <li>INDEX_TIME.merge(SEARCH_TIME) throws an {@link IllegalStateException}</li> | ||
* </ul> | ||
*/ | ||
abstract AnalysisMode merge(AnalysisMode other); | ||
} |
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
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
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
Oops, something went wrong.