meilisearch-java icon indicating copy to clipboard operation
meilisearch-java copied to clipboard

MeiliSearchApiException throw due to `Json deserialize error`

Open Andoctorey opened this issue 3 years ago • 10 comments

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 =, !=, >=, >, <=, <, TO or _geoRadius at [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.

Andoctorey avatar Mar 29 '22 13:03 Andoctorey

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 avatar Mar 29 '22 14:03 alallema

@alallema Do you mean don't use Kotlin and use Java?

Andoctorey avatar Mar 29 '22 14:03 Andoctorey

Just tried pure Java calls - have same error.

Andoctorey avatar Mar 30 '22 02:03 Andoctorey

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.

TomBastable avatar Mar 30 '22 12:03 TomBastable

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

alallema avatar Mar 30 '22 14:03 alallema

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.

TomBastable avatar Mar 30 '22 14:03 TomBastable

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'}

cuongdxk57 avatar May 25 '22 04:05 cuongdxk57

We removed this from our stack for now and just use Ktor to query the server now.

TomBastable avatar May 25 '22 09:05 TomBastable

hello, I encounter the similar issue using Kotlin. Is there any development ?

mayangzz avatar Sep 15 '22 03:09 mayangzz

Hi @mayangzz, Not yet, but the SDK is being rewritten I hope it will be available soon!

alallema avatar Sep 15 '22 07:09 alallema

@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 of q, offset, limit, page, hitsPerPage, attributesToRetrieve, attributesToCrop, cropLength, attributesToHighlight, showMatchesPosition, filter, sort, facets, highlightPreTag, highlightPostTag, cropMarker, matchingStrategy at 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?

MoustafaElsaghier avatar Jan 03 '23 15:01 MoustafaElsaghier

Hi @MoustafaElsaghier, As explained in this issue #494, the latest version of this SDK is currently only compatible with Meilisearch v0.27 at most.

alallema avatar Jan 04 '23 09:01 alallema

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'

MoustafaElsaghier avatar Jan 04 '23 11:01 MoustafaElsaghier

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 avatar Feb 24 '23 15:02 brunoocasali

@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

MoustafaElsaghier avatar Feb 24 '23 15:02 MoustafaElsaghier

This issue should finally be resolved as the SDK has been updated to version v0.30.0 of Meilisearch

alallema avatar Feb 27 '23 18:02 alallema