meilisearch-java
meilisearch-java copied to clipboard
MeiliSearchApiException throw due to `Json deserialize error`
Filter doesn't work for me same as other attributes that requires array. Code example:
val searchRequest = SearchRequest(query).also {
it.matches = true
it.attributesToRetrieve = null
it.limit = limit
it.offset = offset
it.filter = arrayOf("title = media")
}
index.search(searchRequest)
This returns:
MeiliSearchApiException{error=APIError{message='Was expecting an operation
=,!=,>=,>,<=,<,TOor_geoRadiusat[Ljava.lang.String;@8f8841a. 1:28 [Ljava.lang.String;@8f8841a', code='invalid_filter', type='invalid_request', link='https://docs.meilisearch.com/errors#invalid_filter'}} at com.meilisearch.sdk.MeiliSearchHttpRequest.post(MeiliSearchHttpRequest.java:90) at com.meilisearch.sdk.Search.rawSearch(Search.java:93) at com.meilisearch.sdk.Search.search(Search.java:166) at com.meilisearch.sdk.Index.search(Index.java:284)
I checked in debug what library sends:
api = /indexes/global/search body = {"q":"","offset":0,"limit":20,"cropLength":200,"matches":true,"filter":"[Ljava.lang.String;@169dc22"}
It looks like there is issue with json serializer in your library, please fix.
Hi @Andoctorey, You can write your request this way:
SearchRequest searchRequest =
new SearchRequest(query)
.setMatches(true)
.setAttributesToRetrieve(null)
.setLimit(limit)
.setOffset(offset)
.setFilter(new String[] {"title = media"});
index.search(searchRequest);
It should work.
@alallema Do you mean don't use Kotlin and use Java?
Just tried pure Java calls - have same error.
I'm having almost exactly the same issue here. I've spoken to Amelie via the Meili Slack - we're going to try upgrading the server to 0.26 and the library to 0.7.1 to see if that helps at all. Neither Kotlin or Java yields different results.
HI @TomBastable,
Sorry for the delay and thanks for adding your problem here! I think @Andoctorey is right, it is probably due to the json serializer. Can you give more details about your environment? That I am able to reproduce the error?
Thanks
thanks @alallema ! I'm using Android Studio 2021.1.1 patch 2 (bumblebee). Kotlin ver: ext.kotlin_version = '1.6.20-RC2'. It fails on all searches (getDocuments() seems to work though). Same error happens when run from a Java class too, as Andrey mentioned above. Search is structured like so:
val res = testsIndex.search( SearchRequest("", 0, 5000) .setFilter(arrayOf(FilterManager().filterString())) .setMatches(true) )
It might be worth mentioning that FilterManager().filterString() is null / empty in the above sample.
I get the same error message when using Android Studio, but it run correctly on Eclipse
MeiliSearchApiException{error=APIError{message='Json deserialize error: invalid type: string "[Ljava.lang.String;@2eb4bb4", expected a sequence at line 1 column 87', code='bad_request', type='invalid_request', link='https://docs.meilisearch.com/errors#bad_request'}
We removed this from our stack for now and just use Ktor to query the server now.
hello, I encounter the similar issue using Kotlin. Is there any development ?
Hi @mayangzz, Not yet, but the SDK is being rewritten I hope it will be available soon!
@alallema I'm trying to use it in kotlin
val client = Client(Config("URL",
"API_KEY"))
val index: Index = client.index("API_INDEX")
// Meilisearch is typo-tolerant:
val results: SearchResult = index.search(query)
Timber.d("RESULT => $results")
but, I'm getting error messages in catch block
Meilisearch ApiException: {Error=APIError: {message='Json deserialize error: unknown field
matches, expected one ofq,offset,limit,page,hitsPerPage,attributesToRetrieve,attributesToCrop,cropLength,attributesToHighlight,showMatchesPosition,filter,sort,facets,highlightPreTag,highlightPostTag,cropMarker,matchingStrategyat line 1 column 67', code='bad_request', type='invalid_request', link='https://docs.meilisearch.com/errors#bad_request'}}
so, is there any suggestion why that happens, as far for me I'm doing the search query but, it's not happening so, can you let me am I missing anything from my side?
Hi @MoustafaElsaghier, As explained in this issue #494, the latest version of this SDK is currently only compatible with Meilisearch v0.27 at most.
so, what should I do?
should I change the version on my side or what?
this is my current version
implementation 'com.meilisearch.sdk:meilisearch-java:0.8.0'
TL;DR: Try it with latest meilisearch-java v0.10.0.
Hi @MoustafaElsaghier, sorry for the delay. I don't know if the issue is still happening, but we release Meilisearch Java v0.9.0 and Meilisearch Java v0.10.0, which supports v0.28 and v0.29, respectively.
Oh, and we're about to support v0.30 very soon.
The error Meilisearch ApiException: {Error=APIError: {message='Json deserialize error: unknown field matches, expected one of happened because you're trying to use old features in a new version of the Meilisearch engine (v0.28) https://blog.meilisearch.com/whats-new-in-v0-28/.
CC: @alallema
@brunoocasali to be honest that's good news for me but, I've done it through the APIs as I can see that SDK will be delayed sometimes.
really appreciate your hard work here guys
This issue should finally be resolved as the SDK has been updated to version v0.30.0 of Meilisearch