Elasticsearch multi search api is not working properly

Hi,
Im using elasticsearch 8.3.2. Im facing the issue while using multi search api.

API: https://elasticrunningserver:9200/myindex/_msearch
Payload:

{ }
{"query" : {"match" : { "message": "this is a test"}}}
{"query" : {"match_all" : {}}}

Response:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "key [query] is not supported in the metadata section"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "key [query] is not supported in the metadata section"
    },
    "status": 400
}

Please guide me how to fix this.

  • Thanks

Hi @sheiks2m

Read more about Multi Search API

The correct example is

GET my-index-000001/_msearch
{ }
{"query" : {"match" : { "message": "this is a test"}}}
{"index": "my-index-000002"}
{"query" : {"match_all" : {}}}

Hi @RabBit_BR ,

Actually, i created index properly and updated mappings too. Everything is good but when i try to execute multi search query im facing that exception. I tried with correct example too.. again same exception. Is anything related to security/privileges/user privileges?..im not sure about it. help me the same

Execute with this payload:

{ }
{"query" : {"match" : { "message": "this is a test"}}}

After add new query:

{}
{"query" : {"match" : { "message": "this is a test"}}}
{}
{"query" : {"match_all" : {}}}

Tell me if it worked

1 Like

Hi @RabBit_BR ,

Thanks for your response. Its working fine as expected.
But another scenario, Im using Java High level rest client version 7.17.5. Im applying the same but it doesnt work. Please find the below code

SearchSourceBuilder metaDataSearch = new SearchSourceBuilder();
        org.elasticsearch.action.search.SearchRequest metaSearch = new org.elasticsearch.action.search.SearchRequest().source(metaDataSearch).indices(indexName);

SearchSourceBuilder keywordExactRequestBuilder = new SearchSourceBuilder().size(10);
keywordExactRequestBuilder.query(QueryBuilders.matchAllQuery());
org.elasticsearch.action.search.SearchRequest keywordExactRequestSearch = new org.elasticsearch.action.search.SearchRequest().source(keywordExactRequestBuilder).indices(indexName);

MultiSearchRequest multiSearchRequest = new MultiSearchRequest()
                .add(metaSearch)
                .add(keywordExactRequestSearch);

MultiSearchResponse multiSearchResponse = null;
        try {
            multiSearchResponse = elasticClient.msearch(multiSearchRequest, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        }

Im facing the below exception

org.jboss.resteasy.spi.UnhandledException: ElasticsearchStatusException[Elasticsearch exception [type=illegal_argument_exception, reason=key [types] is not supported in the metadata section]]
.......
Caused by: 
ElasticsearchStatusException[Elasticsearch exception [type=illegal_argument_exception, reason=key [types] is not supported in the metadata section]]
......

Im enabled API compatibility mode. Im using elasticsearch version 8.3.2

Thanks

You are better off creating a new topic for that as it's a different client library :slight_smile:

1 Like

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