typesense / typesense-java

Java client for Typesense
https://typesense.org/docs/latest/api/
Apache License 2.0
58 stars 28 forks source link

Nested support. Not yet in latest version? #28

Closed s-gal closed 1 year ago

s-gal commented 1 year ago

Description

There should be a possibility to set enable_nested_fields-option when creating a collection and also the object and object[] should be possible to set with the java library.

Typesense Version:

typesense: 0.24 typesense-java: 0.0.8

s-gal commented 1 year ago

For now i would be happy to know how if there might be a workaround to pass typesense the enable_nested_fields-option. The class CollectionSchema seemes not to allow to pass options when creating a new collection that are not listed there explicitly... For the fields i can set at least object[] if i set the field-type hardcoded as String, but without the enable_nested_fields-option being activated it seemes not to be supported.

kishorenc commented 1 year ago

We need to add this to the Java library. We will prioritise.

kishorenc commented 1 year ago

@s-gal

I've just published ~0.0.9-beta2~ 0.0.9-beta3 version. Can you please check? Once you confirm, I will promote it to a non-beta version number.

kishorenc commented 1 year ago

Sorry, try it against 0.0.9-beta3.

s-gal commented 1 year ago

Somehow since version 0.0.4 (i am using still 0.0.3) i get this stacktrace when starting my application and i am not able to fix it yet:

START NON-TRANSLATABLEjava.lang.ExceptionInInitializerError
sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.

    at java.base/java.lang.J9VMInternals.ensureError(J9VMInternals.java:184)
    at java.base/java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:173)
Caused by: java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found.
Caused by: java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found.

    at org.apache.logging.log4j.LogManager.callerClass(LogManager.java:576)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:601)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:588)
    at de.egetrans.itr.backend.Application.<clinit>(Application.java:19)

Seemes somehow connected to log4j and maybe some conflict between the versions? I know this is not relevant to this current change you made but i am currently not able to test the change because of this stacktrace showing up when starting my application.

kishorenc commented 1 year ago

Does the application quit after the error?

Can you also tell me what version of Java you are using whether you get the same error on a simple vanilla Java console application using just Typesense as dependency.

s-gal commented 1 year ago

Yes it quits right after the error. I am using this Java version: 11.0.12 (Eclipse OpenJ9 / Windows Server 2019)

Maybe the solution is somehow connected to this issue, but not sure how to fix it my environment where i use gradle to build my application: https://stackoverflow.com/questions/52953483/logmanager-getlogger-is-unable-to-determine-class-name-on-java-11

kishorenc commented 1 year ago

@s-gal

I've added the Multi-Release attribute in 0.0.9-beta5 version. Please try with that.

s-gal commented 1 year ago

@kishorenc

thanks very much. it builds now and the enableNestedFields-method is present.

If you could also extend the FieldTypes-class by OBJECTand OBJECT_ARRAY it would be perfect. But it works if i use a String containing object or object[] as well.

How do i need to escape the nested objects data when puting it into a data collection? Or should it work without escaping { } [ ] ? Could you share an example?

kishorenc commented 1 year ago

I've added support for field types in 0.0.9-beta6.

How do i need to escape the nested objects data when puting it into a data collection? Or should it work without escaping { } [ ] ? Could you share an example?

See an example here: https://github.com/typesense/typesense-java/blob/fce39e48b02b8bf5e3447ef999b4efbab2b9a9eb/src/test/java/org/typesense/api/DocumentsTest.java#L199

kishorenc commented 1 year ago

Fixed in 0.0.10 that has been published now.