Skip to content

Commit ccc0a35

Browse files
committed
Revert "Fix field mapping updates with similarity (#33634)"
This reverts commit 831ddf7.
1 parent 831ddf7 commit ccc0a35

File tree

3 files changed

+12
-50
lines changed

3 files changed

+12
-50
lines changed

server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
112112
public boolean equals(Object o) {
113113
if (!super.equals(o)) return false;
114114
MappedFieldType fieldType = (MappedFieldType) o;
115+
// check similarity first because we need to check the name, and it might be null
116+
// TODO: SimilarityProvider should have equals?
117+
if (similarity == null || fieldType.similarity == null) {
118+
if (similarity != fieldType.similarity) {
119+
return false;
120+
}
121+
} else {
122+
if (Objects.equals(similarity.name(), fieldType.similarity.name()) == false) {
123+
return false;
124+
}
125+
}
115126

116127
return boost == fieldType.boost &&
117128
docValues == fieldType.docValues &&
@@ -121,8 +132,7 @@ public boolean equals(Object o) {
121132
Objects.equals(searchQuoteAnalyzer(), fieldType.searchQuoteAnalyzer()) &&
122133
Objects.equals(eagerGlobalOrdinals, fieldType.eagerGlobalOrdinals) &&
123134
Objects.equals(nullValue, fieldType.nullValue) &&
124-
Objects.equals(nullValueAsString, fieldType.nullValueAsString) &&
125-
Objects.equals(similarity, fieldType.similarity);
135+
Objects.equals(nullValueAsString, fieldType.nullValueAsString);
126136
}
127137

128138
@Override

server/src/main/java/org/elasticsearch/index/similarity/SimilarityProvider.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import org.apache.lucene.search.similarities.Similarity;
2323

24-
import java.util.Objects;
25-
2624
/**
2725
* Wrapper around a {@link Similarity} and its name.
2826
*/
@@ -50,28 +48,4 @@ public Similarity get() {
5048
return similarity;
5149
}
5250

53-
@Override
54-
public boolean equals(Object o) {
55-
if (this == o) return true;
56-
if (o == null || getClass() != o.getClass()) return false;
57-
SimilarityProvider that = (SimilarityProvider) o;
58-
/**
59-
* We check <code>name</code> only because the <code>similarity</code> is
60-
* re-created for each new instance and they don't implement equals.
61-
* This is not entirely correct though but we only use equality checks
62-
* for similarities inside the same index and names are unique in this case.
63-
**/
64-
return Objects.equals(name, that.name);
65-
}
66-
67-
@Override
68-
public int hashCode() {
69-
/**
70-
* We use <code>name</code> only because the <code>similarity</code> is
71-
* re-created for each new instance and they don't implement equals.
72-
* This is not entirely correct though but we only use equality checks
73-
* for similarities a single index and names are unique in this case.
74-
**/
75-
return Objects.hash(name);
76-
}
7751
}

test/framework/src/main/java/org/elasticsearch/index/mapper/FieldTypeTestCase.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ public void normalizeOther(MappedFieldType other) {
8989
other.setIndexAnalyzer(new NamedAnalyzer("foo", AnalyzerScope.INDEX, new StandardAnalyzer()));
9090
}
9191
},
92-
// check that we can update if the analyzer is unchanged
93-
new Modifier("analyzer", true) {
94-
@Override
95-
public void modify(MappedFieldType ft) {
96-
ft.setIndexAnalyzer(new NamedAnalyzer("foo", AnalyzerScope.INDEX, new StandardAnalyzer()));
97-
}
98-
@Override
99-
public void normalizeOther(MappedFieldType other) {
100-
other.setIndexAnalyzer(new NamedAnalyzer("foo", AnalyzerScope.INDEX, new StandardAnalyzer()));
101-
}
102-
},
10392
new Modifier("search_analyzer", true) {
10493
@Override
10594
public void modify(MappedFieldType ft) {
@@ -148,17 +137,6 @@ public void normalizeOther(MappedFieldType other) {
148137
other.setSimilarity(new SimilarityProvider("bar", new BM25Similarity()));
149138
}
150139
},
151-
// check that we can update if the similarity is unchanged
152-
new Modifier("similarity", true) {
153-
@Override
154-
public void modify(MappedFieldType ft) {
155-
ft.setSimilarity(new SimilarityProvider("foo", new BM25Similarity()));
156-
}
157-
@Override
158-
public void normalizeOther(MappedFieldType other) {
159-
other.setSimilarity(new SimilarityProvider("foo", new BM25Similarity()));
160-
}
161-
},
162140
new Modifier("eager_global_ordinals", true) {
163141
@Override
164142
public void modify(MappedFieldType ft) {

0 commit comments

Comments
 (0)