Proper way to work with search dropdown and external queries


#1

Hi guys, I have a little problem. The thing is that I have two dropdown lists that each one is in charge of searching the records in the database for a specific field. For this, I have a query defined for each dropdown list, something like the following:

async function getStateSearchedData() {
  const result = await cf.provider('Elasticsearch')
                         .source('index-to-search')
                         .rows(['state_desc'])
                         .textfilter('state_desc:Texas')
                         .limit(1000)
                         .element('my-query-id')
                         .execute();

  return result.data;
}

The other query is the same but the field in the rows is another one.

The query runs fine, and I get the data. The problem is that when I add another filter to the Interaction Manager, for example by clicking on a bar chart, the two queries created for the two dropdown lists are executed as well, but I want to avoid that behavior since I only need those queries to get the data every time I do a search.

Any suggestion about it?


#2

Hello @karla.cryan, what is happening is that when you create the queries to carry out your search, they remain registered, and then when you add another filter, the Interaction Manager also selects them and applies the filter to them if the field of the new filter belongs to the metadata fields of each query.

In this case, what you should do is what is explained in the After executing your query section of the documentation related to Querying Data.