`.sourceExclude` and `.sourceInclude` are mutually exclusive
tastyminerals opened this issue · 1 comments
tastyminerals commented
Currently you can't use sourceExclude
and sourceInclude
together when constructing a SearchRequest
. The latter will overwrite the former.
val request = search("test_index")
.query(matchAllQuery)
.sourceExclude(Seq("doc_id"))
.sourceInclude(Seq("user_id"))
request.show
produces
POST /upload_read/_search
{"query":{"match_all":{}},"_source":{"includes":["user_id"]}}
In case the sourceInclude(Seq.empty)
, the request excludes will be similarly removed completely, producing "_source":true
.
This could be the intended behavior, I am not sure because there is no documentation and no tests for using both of these functions. However, the classic elasticsearch library allows it and anyone who attempts a migration will end up having nasty silent bugs.
new SearchSourceBuilder().query(query).fetchSource(Array("doc_id"), Array("user_id"))