-
Notifications
You must be signed in to change notification settings - Fork 33
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
JSONObject
now returns real types. You can still useJSONObject
by using the jackson-datatype-json-org library - All methods on
UserKey
are now just namedKey
(eg:listUserKeys
=>listKeys
) -
searchDisjunctiveFaceting
was removed -
addObject(obj, objectId)
has its parameters swappedindex.addObject(objectId, obj)
-
waitTask
was moved to theTask
class - All
getXXX
methods now returns anOptional<T>
- All methods returning
JSONObject
now returns real types. You can still useJSONObject
by using the jackson-datatype-json-org library -
listIndexes
was 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.copyIndex
was moved toindex.copyTo(dst)
-
client.moveIndex
was moved toindex.moveTo(dst)
- Move all setters to the builder
- Remove
enableRateLimitForward
- renamed
attributes
toattributesToRetrieve
- renamed
numerics
numericFilters
- renamed
tags
totagsFilters
- renamed
maxNumberOfFacets
tomaxValuesPerFacet
- renamed
aroundLatLong
toaroundLatLng
- renamed
aroundLatLongViaIP
toaroundLatLngViaIP
- removed
noTypoToleranceOn
,similarQuery
andreferers
- package
com.algolia.search.saas
was renamedcom.algolia.search
-
APIClient.IndexQuery
was moved to its own fileIndexQuery
-
Index.IndexBrowser
was deleted and replaced byIndexIterable<T>
. It is now anIterable
. To get an iterator call theiterator()
method
- The
Index
class can now be parametrized with a concrete type. Useclient.initIndex("myIndex", MyPojo.class)
- Each method of the
Index
class 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
ObjectMapper
to the builder. It's overriden with specific configuration, you can find the overrides incom.algolia.search.Defaults.DEFAULT_OBJECT_MAPPER
. - Each method parameter that must not be
null
is now annotated with the annotation@Nonnull
- A
stream()
method is available toIndexIterable
- In the
Query
class- 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.