Search Query API Call Configuration for more than one conditions


I've been trying the API call from the Search Applications > Connect features. Can see the screenshot and below is the sample :

POST /_application/search_application/search-my/_search
  "params": {
    "query": "pizza",
    "myCustomParameter": "example value"

We would like to do API call direct to our search engine, rather than Elasticsearch.

We trying to set the params query according to below conditions :

query condition:

  • match keyword in title, description, postfiles
  • isprivate = false or (isprivate = true and users_in_channel = userId)
  • published date in range date

To give you explanation, first condition, we need to set the params to read if match the search query with any field in the data field which is 'title', 'description', 'postfiles', then it will show the search result, this is the first condition.

Second condition, to check the query with the data in search engine, if its match where, if it (isprivate = true and users_in_channel = userId) or if it is not private (isprivate = false).

Lastly, to check the published_date if its within the range date that user filter from the frontend ui, this parameter will be passed also through API to check the range date and filter the data based on this parameter.

Below is our API call that works :

GET /_application/search_application/search-my/_search
  "params": {
    "query_string": "(1234) OR (Testing)"
GET /_search
    "query": {
        "multi_match": {
            "query": "(1234) OR (Testing)",
            "fields": ["users_in_channel","title"]

We've been testing around the API and not sure if this is the correct way to set the params for search query.

Need help to construct the API based on mentioned conditions.

Hi @aisyaharifin I'm happy to see that you're experimenting with search applications!

It looks like you've already started setting it up, but in case you haven't found it we have a pretty good overview document on setting up search applications.

When you create a search application, you can pass in a search template to the search application. This template represents the query that you'd send into the search application when you use the _application/<>/_search endpoint. If you choose not to specify a search template, a default template will be applied and used in the search application. Currently the default template performs a simple query_string query over the indices in your search application. You'd send in parameters to change query_string to whatever value you wanted. You can check the template at any time using the get API and update it at any time using the put API.

Now, the good news is that when the search application is created, an alias is also created for that search application using the same name - so you can search over the same indices using the regular _search API call like you want, and it will search that alias. However, if you don't use the search application search API the template won't be used, so you have to modify the _search query to search for what you want.

Hope that helps.

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