elastic / elastic/elasticsearch-java

Can't use _source array with SearchRequest withJson

Open
#400 3 comments 3 reactions 0 assignees View on GitHub
Category: Enhancement
Dominant language
Java
Stars
524
Forks
300
Avg merge
1d 11h
Merged PRs (30d)
16

Description

### Java API client version

7.17.6

### Java version

17

### Elasticsearch Version

7.17.6

### Problem description

I'm trying to create a `SearchRequest` from a search request expressed as json using the `withJson` method.

`SearchRequest sr = SearchRequest.of(b -> b .withJson(strReader).index("myindex"));`

Content of json string in `strReader`:
```
{
"_source": [ "obj1.*", "obj2.*" ],
"query": {
"match": {
"user.id": "kimchy"
}
}
}
```

Used with `withJson` on SearchRequest throws:

`co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch.core.SearchRequest: co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'START_ARRAY' instead of '[START_OBJECT, KEY_NAME, VALUE_STRING, VALUE_TRUE, VALUE_FALSE]' (JSON path: _source) (line no=2, column no=15, offset=16)`

It is working if I limit the `_source` to 1 value (no array) like `"_source": "obj1.*"`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.