Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encounter error when trying search with AttributesToHighlight #687

Open
372475697 opened this issue Nov 21, 2023 · 2 comments
Open

encounter error when trying search with AttributesToHighlight #687

372475697 opened this issue Nov 21, 2023 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@372475697
Copy link

I'm encounter json serialize error when trying search method to get documents via JAVA SDK,
here are the sample code.

image

here is the error stacktrace
Meilisearch ApiException: {Error=APIError: {message='Invalid value type at .attributesToHighlight: expected an array, but found a string: "**[Ljava.lang.String;@10fc5e2f**"', code='invalid_search_attributes_to_highlight', type='invalid_request', link='https://docs.meilisearch.com/errors#invalid_search_attributes_to_highlight'}}

pls refer the highlighted part, I noticed that org.json.JSONObject wrongly serialize the String arrary to [Ljava.lang.String;@10fc5e2f
any idea to reslove this issue? as workaround, I'm using JAVA API to do the search instead temporary.

Environment (please complete the following information):

  • OS: windows 10
  • Meilisearch version: v1.4.2
  • meilisearch-java version: v0.11.5
  • org.json version: 20231013, as sdk pom required
@brunoocasali
Copy link
Member

Do you know if that only happens when you try to use the SearchResultPaginated?

@songxychn
Copy link

songxychn commented Jan 13, 2024

i have a similar issue when using SearchRequestBuilder.

by debug, i found that SearchRequest.toString() converted array fields like attributesToHighlight to [Ljava.lang.String;@xxxxxx instead of ["xxx", "yyy"]

the toString method uses org.json.JSONObject to convert object to json string. obviously the org.json.JSONObject can't handle array fields as we expect.

i found that the class i use is actually org.json.JSONObject from com.vaadin.external.google:android-json instead of org.json

if you remove com.vaadin.external.google:android-json from your project like below, the problem will be fixed.

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>com.vaadin.external.google</groupId>
            <artifactId>android-json</artifactId>
        </exclusion>
    </exclusions>
</dependency>

then it's easy to understand why some users meet this bug but the developers can't reproduce it(like #573)

more background information can be found here: https://stackoverflow.com/a/60952911/19414568

Environment (please complete the following information):

OS: macos 13.4.1

jdk: 21

springboot: 3.2.0

Meilisearch version: v1.5

meilisearch-java version: v0.11.5

@curquiza curquiza added bug Something isn't working good first issue Good for newcomers labels Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants