# ElasticSearch filter results by multiple ORs not working

**URL:** <https://discuss.elastic.co/t/elasticsearch-filter-results-by-multiple-ors-not-working/81184>\
**Category:** Elasticsearch\
**Created:** [April 4, 2017, 4:52pm UTC](https://discuss.elastic.co/t/elasticsearch-filter-results-by-multiple-ors-not-working/81184 "2017-04-04T16:52:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CutThis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cutthis/32/17062_2.png) [@CutThis](https://discuss.elastic.co/u/CutThis)\
**Post date:** [April 4, 2017, 4:52pm UTC](https://discuss.elastic.co/t/elasticsearch-filter-results-by-multiple-ors-not-working/81184/1 "2017-04-04T16:52:22Z")

</div>

I'm trying to query results similar to (totally new with ES):

`$query = 'select * from promoter where (id_assigned_topic = ' . $id_topic . ' or id_topic_father = ' . $id_topic . ' or id_topic_grandfather = ' . $id_topic . ') and lower(name) like "%' . $search . '%" order by ranking DESC LIMIT ' . $limit_low . ',' . ($limit_high - $limit_low) . ';';`

and I have built this search query for ElasticSearch:

```
$params = [
            'index' => 'es_promoters',
            'type' => 'data',
            'from' => $limit_low, 
            'size' => ($limit_high - $limit_low),
            'body' => [

                  "query"=> [
                    "bool"=> [
                      "must"=>[
                                "query_string" => [
                                                        "fields" => ["name"],
                                                        "query" => $search 
                                                    ],
                                "query_string" => [
                                                        "fields" => ["name"],
                                                        "query" => '"' . $search . '"'
                                                    ],
                                "query_string" => [
                                                        "fields" => ["name"],
                                                        "query" => '*' . $search . '*'
                                                    ],

                                ],
                                 "filter" =>[
                                        "bool" => [
                                                 "should" => [ 
                                                             "term" => ["id_assigned_topic" => $id_topic],
                                                             "term" => ["id_topic_father" => $id_topic],
                                                             "term" => ["id_topic_grandfather" => $id_topic],
                                                            ],
                                                "minimum_should_match" => 1
                                                ]
                                            ]

                            ]
                          ],

                ]
            ];

```

If I remove everything from the "filter" part I get all the results to match the names, however I cannot do an OR between the topic\_ids.

my questions would be:

how can I do an OR between the various topic\_ids?  
how do I sort the final results descending by ranking?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 2, 2017, 4:52pm UTC](https://discuss.elastic.co/t/elasticsearch-filter-results-by-multiple-ors-not-working/81184/2 "2017-05-02T16:52:28Z")

</div>

Closed on May 2, 2017, 4:52pm UTC

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