Plugin dev - callWithRequest multi_match query

Hi all,

I'm trying to get started on a Kibana plugin.

I have managed to setup some simple data entry form and display the results in a table. However, I'm trying to perform a multi_match query with callWithRequest, but I don't see what is wrong. Perhaps you have some pointers..

resp = await callWithRequest(req, 'search', {
  index: 'test-index',
  size: 10,
  body: {
    query: {
      match: {
        message: { query }
      }
    }
  }
  }

)

Is working just fine, but now I want to edit the query to perform a multi_match on all fields in the index (Expensive query, I know).

I figured since the 'reqular 'query is:
"query": { "multi_match" : { "query": "searchthis", "fields": [ "*" ] } }

I could rewrite the code to:

resp = await callWithRequest(req, 'search', {
  index: 'test-index',
  size: 10,
  body: {
    query: {
      multi_match: {
        query: { query },
          fields: ["*"]
        }
       }
      }
    }

`
But this is giving an error

{"msg":"[parsing_exception] [multi_match] unknown token [START_OBJECT] after [query], with { line=1 & col=34 }","path":"/test-index/_search","query":{"size":10},"body":"{"query":{"multi_match":{"query":{"query":"abcd"},"fields":["*"]}}}","statusCode":400,"response":"{"error":{"root_cause":[{"type":"parsing_exception","reason":"[multi_match] unknown token [START_OBJECT] after [query]","line":1,"col":34}],"type":"parsing_exception","reason":"[multi_match] unknown token [START_OBJECT] after [query]","line":1,"col":34},"status":400}"}

I can't seem to figure out why this is not working.. Any tips?

This:

will result in:

query: {query: value_of_query_variable}

I believe what you need is:

resp = await callWithRequest(req, 'search', {
  index: 'test-index',
  size: 10,
  body: {
    query: {
      multi_match: {
        query,
        fields: ["*"]
       }
     }
  }
}
1 Like

Thanks! This actually makes sense now as well.

I had put this functionality aside for the time being, but works flawless! Sometimes you just get stuck and dont see what's what.

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