# Search on Multiple Indices

**URL:** <https://discuss.elastic.co/t/search-on-multiple-indices/307105>\
**Category:** Elasticsearch\
**Created:** [June 14, 2022, 7:49am UTC](https://discuss.elastic.co/t/search-on-multiple-indices/307105 "2022-06-14T07:49:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![QuanMinhTran](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quanminhtran/32/106984_2.png) [@QuanMinhTran](https://discuss.elastic.co/u/QuanMinhTran)\
**Post date:** [June 14, 2022, 7:49am UTC](https://discuss.elastic.co/t/search-on-multiple-indices/307105/1 "2022-06-14T07:49:41Z")

</div>

I doing a query to search for multiple indices on Elasticsearch. The problem here is the priority of the result doesn't follow what I think.

For example, I have 2 indices: index\_1 and index\_2

In Index\_1 have ~80 docs, contain:

- Doc\_1\_A: contain 2 keyword "test search"
- Doc\_1\_B: contain 1 keyword "test search"

In Index\_2 have ~10 docs, contain:

- Doc\_2\_A: contain 2 keyword "test search"

my request:

```auto
***/index_1,index_2/_search)

```

my query:

```auto
{
    "query": {
        "bool": {
            "must": [
                {
                    "query_string": {
                        "fields": [
                            "Name",
                            "Desc"
                        ],
                        "query": "test search",
                        "analyzer": "whitespace",
                        "fuzziness": "AUTO",
                        "default_operator": "AND"
                    }
                }
            ]
        }
    },
    "size": 20,
    "highlight": {
        "require_field_match": true,
        "fields": {
            "*": {
                "fragment_size": 100,
                "number_of_fragments": 1
            }
        }
    }
}

```

The result I got after the request search show the priority like this:  
Doc\_1\_A \>\> Doc\_1\_B \>\> Doc\_2\_A  
What I expect is: (since Doc\_2\_A has more match keyword than Doc\_1\_B)  
Doc\_1\_A \>\> Doc\_2\_A \>\> Doc\_1\_B

I do read about the score of ES, it got affected by the TF and IDF (the result got mess up cause the number of docs in Index\_1 is much more larger than the Index\_2). The score of Doc\_2\_A is much more smaller than Doc\_1\_B, this is why the priority doesn't look like what I expect.

When I reindex my two indices into one ( index\_merged ), and then search on that mutual index, the result would be like what I expect. But with this new index, I can't update this when there is a new doc or a doc got removed.

But if I search on multi index like my query, I can't get what I expect.

So there is any way to help me with this?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [June 14, 2022, 7:52pm UTC](https://discuss.elastic.co/t/search-on-multiple-indices/307105/2 "2022-06-14T19:52:14Z")

</div>

I've been through a similar situation, my indexes had different mappings with some fields in common and I chose [multi search](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html) instead of your approach.  
I was reading the doc and saw that you can [boost indices](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multiple-indices.html#index-boost) individually, I don't know if it can help you.

---

<div class="post-metadata">

**Author:** ![QuanMinhTran](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quanminhtran/32/106984_2.png) [@QuanMinhTran](https://discuss.elastic.co/u/QuanMinhTran)\
**Post date:** [June 16, 2022, 8:49am UTC](https://discuss.elastic.co/t/search-on-multiple-indices/307105/3 "2022-06-16T08:49:43Z")

</div>

Thanks for your reply,

I did use the boost indices, it does help me to boost the index I want a little higher.

I did try the new approach with multi search that u mentioned, but it seem a little off and I don't quite get the example show in the page. Can u show me an example with this or any sources that mention about it, it would mean much for me.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [June 16, 2022, 1:03pm UTC](https://discuss.elastic.co/t/search-on-multiple-indices/307105/4 "2022-06-16T13:03:03Z")

</div>

What multi search proposes is to receive one or more queries and return the results to the queries, it will not be just one result.  
Look this example:

```auto
GET _msearch
{"index":"idx_movies"}
{"size":1, "_source": ["title"], "query":{"match_all":{}}}
{"index":"my-index"}
{"size":1, "query":{"match_all":{}}}

```

Response:

```auto
{
  "took" : 3,
  "responses" : [
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1001,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "idx_movies",
            "_type" : "_doc",
            "_id" : "vpwMOYEBBR941NShMW3o",
            "_score" : 1.0,
            "_source" : {
              "title" : "Guardians of the Galaxy"
            }
          }
        ]
      },
      "status" : 200
    },
    {
      "took" : 2,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 2,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "my-index",
            "_type" : "_doc",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "my_text" : "text1",
              "my_vector" : [
                0.5,
                10,
                6
              ]
            }
          }
        ]
      },
      "status" : 200
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![QuanMinhTran](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quanminhtran/32/106984_2.png) [@QuanMinhTran](https://discuss.elastic.co/u/QuanMinhTran)\
**Post date:** [June 17, 2022, 3:31am UTC](https://discuss.elastic.co/t/search-on-multiple-indices/307105/5 "2022-06-17T03:31:05Z")

</div>

Thanks, I will try to do this with your example.

---

<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:** [July 15, 2022, 3:31am UTC](https://discuss.elastic.co/t/search-on-multiple-indices/307105/6 "2022-07-15T03:31:12Z")

</div>

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