ContainsAny not working with text[] in JAVA
defined: Property.builder().dataType(Collections.singletonList("text[]")); DATA:["a1","b1","c1"]
GraphQLError(message=Argument "where" has invalid value {path: ["tags"], valueString: ["["ai","c1"]"], operator: ContainsAny}. In field "operator": Expected type "GetObjectsTest03WhereOperatorEnum", found ContainsAny. In field "valueString": Expected type "String", found ["["ai","c1"]"]., path=null, locations=[GraphQLErrorLocationsItems(column=19, line=1)])
Array queries have always been problematic in java, and various methods are used to handle arrays.
.valueString(new Gson().toJson(Arrays.asList("ai", "c1"))) is tried
GraphQLResponse(data=null, errors=[GraphQLError(message=Argument "where" has invalid value {path: ["tags"], valueText: ["a1", "b1"], operator: ContainsAny}. In field "operator": Expected type "GetObjectsTest03WhereOperatorEnum", found ContainsAny. In field "valueText": Expected type "String", found ["a1", "b1"]., path=null, locations=[GraphQLErrorLocationsItems(column=19, line=1)])])
hi @D-nani! Sorry it took me a bit longer to get around to this. Anyways, thank you for reaching out to us.
There are some things you could improve about the way your query is built. Can you try this out to see if it works?
WhereFilter filter = WhereFilter.builder()
.path("tags") // No need to create an array explicitly
// 1) pass string literals, not JSON-array-string and
// 2) prefer valueText, as valueString's been deprecated
.valueText("ai", "c1")
.operator(Operator.ContainsAny)
.build();
// Wrap your WhereFilter in a WhereArgument before passing it to graphQL().get()
WhereArgument where = WhereArgument.builder().filter(filter).build();
// Finally
client.graphQL().get()
// other options...
.withWhere(where) // Note that this is an overloaded #where(WhereArgument)
.run();
Here's a complete working example:
Config config = new Config("http", address);
WeaviateClient client = new WeaviateClient(config);
client.schema().classCreator().withClass(WeaviateClass.builder()
.className("ExampleFilter")
.properties(new ArrayList<Property>() {
{
add(Property.builder().name("letters").dataType(new ArrayList<String>() {
{
add("text[]");
}
}).build());
}
})
.build()).run();
Result<?> insert = client.data().creator()
.withClassName("ExampleFilter")
.withProperties(new HashMap<String, Object>() {
{
put("letters", new ArrayList<String>() {
{
add("d");
add("e");
add("f");
}
});
}
}).run();
assertThat(insert.getError()).as("insert").isNull();
Result<?> result = client.graphQL().get()
.withFields(Field.builder().name("letters").build())
.withClassName("ExampleFilter")
.withWhere(WhereArgument.builder()
.filter(WhereFilter.builder()
.path("letters")
.operator(Operator.ContainsAny)
.valueText("x", "y", "z", "f")
.build())
.build())
.run();
assertThat(result.getError()).as("get").isNull();
please try it in v6 :)