# Building an index for faster search

**URL:** <https://discuss.elastic.co/t/building-an-index-for-faster-search/326301>\
**Category:** Elasticsearch\
**Created:** [February 23, 2023, 10:30am UTC](https://discuss.elastic.co/t/building-an-index-for-faster-search/326301 "2023-02-23T10:30:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![orlenkoda5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/orlenkoda5/32/117648_2.png) [@orlenkoda5](https://discuss.elastic.co/u/orlenkoda5)\
**Post date:** [February 23, 2023, 10:30am UTC](https://discuss.elastic.co/t/building-an-index-for-faster-search/326301/1 "2023-02-23T10:30:31Z")

</div>

Hi everyone,  
I have one question.  
How should I build my index to reduce the time of searching?  
In my case, using aggregations for distinct search really increases the time of searching.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 23, 2023, 10:48am UTC](https://discuss.elastic.co/t/building-an-index-for-faster-search/326301/2 "2023-02-23T10:48:14Z")

</div>

You have not provided a lot of information, so it is hard to give anything but general advice.

Which version of Elasticsearch are you using?

Have you looked at [the section in the docs around tuning for search speed](https://www.elastic.co/guide/en/elasticsearch/reference/8.6/tune-for-search-speed.html)?

Have you tried using [profiling](https://www.elastic.co/guide/en/elasticsearch/reference/8.6/search-profile.html#profiling-considerations)?

---

<div class="post-metadata">

**Author:** ![orlenkoda5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/orlenkoda5/32/117648_2.png) [@orlenkoda5](https://discuss.elastic.co/u/orlenkoda5)\
**Post date:** [March 14, 2023, 1:49pm UTC](https://discuss.elastic.co/t/building-an-index-for-faster-search/326301/3 "2023-03-14T13:49:35Z")

</div>

Hi, thank you for the answer. I'm using Version 7.17.5.  
I've built an index for the list of clients. This index includes 6253156 docs. Each doc has 8 fields of different types (text, long and date). I need to have a distinct result of searching clients and sort the list of distinct clients in alphabetical order. This sort must include full name sort. So, I decided to use an aggregation in my search and it looks like this:

```auto
 GET clientindex/_search
{
"size": 0,
"query" : {
"bool" : {
"should" : [
{ "term" : { "full_name" : "name surname" } }
]
}
},
"aggs": {
"distinct_full_name": {
"terms": {
"field": "full_name.keyword",
"order": {"_key": "asc"},
"size": 1000
}
}
}
}

```

This search gives me distinct search with docs count, but it takes too much time for searching, sorting and counting. So the question is: how can I build an index to decrease the time of searching? Or, if it'll be better to use another search, please, give some advices. Thank you!

I haven't seen [the section in the docs around tuning for search speed](https://www.elastic.co/guide/en/elasticsearch/reference/8.6/tune-for-search-speed.html) and [profiling](https://www.elastic.co/guide/en/elasticsearch/reference/8.6/search-profile.html#profiling-considerations) yet. I will look for useful information for my case there, thank you a lot.

---

<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:** [April 11, 2023, 1:49pm UTC](https://discuss.elastic.co/t/building-an-index-for-faster-search/326301/4 "2023-04-11T13:49:51Z")

</div>

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