Skip to content

Commit

Permalink
[FIX] Make GeoContext mapping idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
areek committed Apr 15, 2015
1 parent 82df50a commit 98899c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Expand Up @@ -601,7 +601,9 @@ public GeolocationContextMapping build() {
if(precisions.isEmpty()) {
precisions.add(GeoHashUtils.PRECISION);
}
return new GeolocationContextMapping(name, precisions.toArray(), neighbors, defaultLocations, fieldName);
int[] precisionArray = precisions.toArray();
Arrays.sort(precisionArray);
return new GeolocationContextMapping(name, precisionArray, neighbors, defaultLocations, fieldName);
}

}
Expand Down
Expand Up @@ -24,8 +24,10 @@
import org.elasticsearch.action.suggest.SuggestRequest;
import org.elasticsearch.action.suggest.SuggestRequestBuilder;
import org.elasticsearch.action.suggest.SuggestResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand Down Expand Up @@ -153,7 +155,26 @@ public void testMultiLevelGeo() throws Exception {
assertEquals("Hotel Amsterdam in Berlin", suggestResponse.getSuggest().getSuggestion(suggestionName).iterator().next()
.getOptions().iterator().next().getText().string());
}
}
}

@Test
public void testMappingIdempotency() throws Exception {
XContentBuilder mapping = jsonBuilder().startObject().startObject(TYPE)
.startObject("properties").startObject("completion")
.field("type", "completion")
.startObject("context")
.startObject("location")
.field("type", "geo")
.array("precision", 1, 2, 3, 4)
.endObject()
.endObject().endObject()
.endObject().endObject();

assertAcked(prepareCreate(INDEX).setSettings(ImmutableSettings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)).addMapping(TYPE, mapping.string()));
ensureYellow();
assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(mapping.string()).get());
}


@Test
public void testGeoField() throws Exception {
Expand Down

0 comments on commit 98899c5

Please sign in to comment.