How to provide source Field in _msearch query in ElasticSearch java client version 8

My Elasticsearch's documents are of high size. My service is Java application and its using Elasticsearch java client version 8. Need to run _msearch query on ES. MultisearchBody don't have field of _source. in ES native query I can do this by below query

{ "query": { "bool": { "must": { "match_all": {} } } }, "size": 10000, "_source": [ "personName" ]}

Not able to figure-out how to do this in ES-java client version 8?

Hi @maulik_trapasiya

Did you try like this:

    var response = client.msearch(MsearchRequest.of(ms -> ms.searches(
        List.of(RequestItem.of(ri -> ri
                .header(MultisearchHeader.of(mh -> mh.index("idx_teste")))
                .body(MultisearchBody.of(msb -> msb
                    .query(MatchAllQuery.of(ma -> ma)._toQuery())
                    .source(SourceConfig.of(sc -> sc.filter(f -> f.includes(List.of("personName")))))
                    .size(10000)
                ))
            )
        ))),
        Object.class);
1 Like

Thanks @RabBit_BR . In elasticSearch java client maven version 8.2.0 this wasn't available. in latest version 8.8.0 this is available

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.