-
Notifications
You must be signed in to change notification settings - Fork 32
Migration guide from 1.x to 2.x
AlgoliaSearch Java client v2 was introduced to improve type safety, testability, and uses new features in Java 1.8. So the v2, drops support for Java 1.6 & 1.7. With all those improvements come some incompatible changes with the first version of the client. This document is intended to the users of the v1.x of the client who choose to migrate their code from version 1.x to 2.x.
Non-backward compatible changes are affecting all the existing functions from the APIClient and Index classes.
They now provide typed results based on your POJO.
The serialization/deserialization of JSON is made with Jackson2.
If you have any issue, please contact our team at [email protected].
- Migrate your code to v2
- Initialization
- Other breaking changes
- New features
- Fixes
- Misc
- Can I still use v1?
v1
APIClient client = new APIClient("YourApplicationID", "YourAPIKey");v2
APIClient client = new ApacheAPIClientBuilder("YourApplicationID", "YourAPIKey").build();The initialization is now done with a builder, on which you can change the default values.
All the parameters of the class APIClient are now passed to the builder
See the options in the APIClientBuilder class.
To standardise methods signatures, to add type safety and to uses java 1.8 features, some methods have changed their signature.
- All methods returning
JSONObjectnow returns real types - All methods on
UserKeyare now just namedKey(eg:listUserKeys=>listKeys) -
searchDisjunctiveFacetingwas removed -
addObject(obj, objectId)has its parameters swappedindex.addObject(objectId, obj) -
waitTaskwas moved to theTaskclass - All
getXXXmethods now returns anOptional<T>
- All methods returning
JSONObjectnow returns real types. You can still useJSONObjectby using the (jackson-datatype-json-org library)[https://github.com/FasterXML/jackson-datatype-json-org] -
listIndexeswas renamedlistIndices -
getLogs(int offset, int length)was removed, usegetLogs(offset, length, LOG_ALL) -
getLogs(int offset, int length, boolean onlyErrors)was removed, usegetLogs(offset, length, LOG_ERROR) -
client.copyIndexwas moved toindex.copyTo(dst) -
client.moveIndexwas moved toindex.moveTo(dst) - Move all setters to the builder
- Remove
enableRateLimitForward
- renamed
attributestoattributesToRetrieve - renamed
numericsnumericFilters - renamed
tagstotagsFilters - renamed
maxNumberOfFacetstomaxValuesPerFacet - renamed
aroundLatLongtoaroundLatLng - renamed
aroundLatLongViaIPtoaroundLatLngViaIP - removed
noTypoToleranceOn,similarQueryandreferers
- package
com.algolia.search.saaswas renamedcom.algolia.search -
APIClient.IndexQuerywas moved to its own fileIndexQuery -
Index.IndexBrowserwas deleted and replaced byIndexIterable<T>. It is now anIterable. To get an iterator call theiterator()method
- The
Indexclass can now be parametrized with a concrete type. Useclient.initIndex("myIndex", MyPojo.class) - Each method of the
Indexclass now returns specific types based on the concrete type passed at creation time. - All serialization/deserialization is made with Jackson2, you can pass your own
ObjectMapperto the builder. Changing it might result in unexpected result. You can find the one used in the interfacecom.algolia.search.Defaults.DEFAULT_OBJECT_MAPPER. - Each method parameter that must not be
nullis now annotated with the annotation@Nonnull - A
stream()method is available toIndexIterable - In the
Queryclass- add
setAroundRadiusAll() - add
setRemoveStopWords(List<String> isoCode)
- add
Yes. If you are using the v1 of our Java client and do not want to upgrade then you can stick to v1.
Warning New features of the v2 (async, type safety, etc.) won't be back-ported to the v1.