Query String query with multiple terms

I have a quite large index, well at least to me, 3 million records and adds between 500 to 2000 more a day.

There are 150 categories, I want to be able to search for query strings within those categories. There are also youtube videos that are available for each categories (sources, source_id). The search I have tried several different ways to achieve this. The example below, is searching category "source_id: 5, and youtube videos true, sorted descending, top 10, and searching on term NFL.

How do you create a query that does a query string search with multiple exact terms?

{
    "size": 10,
"query" : {
  "bool" : {
    "should" : [
      { "term": { "source_id": 5}},
      { "term": { "youtube": true }}
    ],
    "minimum_should_match": 2
  },
  "query_string": {
    "query": "NFL",
    "default_field": "title"
}
},
    "sort":
        {"created_at": "desc"}

}

Hi Darryl,

Have you tried using filter context?

It would make sense to put youtube: true and source_id: 5 as filter and have your query be a regular query.

I actually have a solution, and I used filter for the terms and query_string.


{
    "size": 10,
  "query": {
    "bool": { 
      "must": [
        {
          "query_string": {
            "query": "Commander",
            "default_field": "title"
          }
        }
      ],
      "filter": [
        {"term": { "youtube" : true }},
        {"term": { "source_id": 14 }}
      ]
    }
  }
}

Thanks....

1 Like

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