# Elasticsearch is not used

**URL:** <https://forum.mattermost.com/t/elasticsearch-is-not-used/11894>\
**Category:** Troubleshooting\
**Created:** [July 7, 2021, 1:07am UTC](https://forum.mattermost.com/t/elasticsearch-is-not-used/11894 "2021-07-07T01:07:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zsyh2619](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/zsyh2619/32/4925_2.png) [@Zsyh2619](https://forum.mattermost.com/u/Zsyh2619)\
**Post date:** [July 7, 2021, 1:07am UTC](https://forum.mattermost.com/t/elasticsearch-is-not-used/11894/1 "2021-07-07T01:07:37Z")

</div>

**Summary**  
I am using the test license. I configured elasticsearch, imported 5 million chat records, and returned 504 when querying. So I did a test to prove that elastic search was not used

**Steps to reproduce**  
I have tried v5.31.0 and v5.36.1,

1. Configure elasticsearch according to the document and close the database search
2. restart the service
3. send some message.
4. then I modified the message in elasticsearch
5. then I modified the message in mysql

**Expected behavior**  
After refreshing the page, I can search the contents in elasticsearch

**Observed behavior**  
Refresh the page and find that the message becomes the content in MySQL

> <https://github.com/mattermost/mattermost-server/issues/17866>
>
> I have tried v5.31.0 and v5.36.1
> I configured elasticsearch, imported 5 million… chat records, and returned 504 when querying. So I did a test:
> 1. Configure elasticsearch according to the document and close the database search
> 2. restart the service
> 3. send some message.
> (I found that new message can be found in elasticsearch)
> 4. then I modified the message in elasticsearch
> (Refresh the page and find that the message has not changed)
> 5. then I modified the message in mysql
> (Refresh the page and find that the message becomes the content in MySQL)
> So its query is still using MySQL instead of elasticsearch
> I read some source code and found that the problem might be found in app/server.go line 360 370 385, this may cause the search to use sqlstore all the time

---

<div class="post-metadata">

**Author:** ![ahmaddanial](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ahmaddanial/32/2938_2.png) [@ahmaddanial](https://forum.mattermost.com/u/ahmaddanial)\
**Post date:** [July 7, 2021, 2:55am UTC](https://forum.mattermost.com/t/elasticsearch-is-not-used/11894/2 "2021-07-07T02:55:30Z")

</div>

Hi, @Zsyh2619

A couple of questions to shed more light on this issue:

- How did you import the 5 million messages into Mattermost? Did you use [bulk loading](https://docs.mattermost.com/deployment/bulk-loading.html) method or something else?
- How did you modify the message in ES? Would you mind sharing some screen shots here?
- When you mentioned that the message became the content in MySQL, can you elaborate a little further on that?

---

<div class="post-metadata">

**Author:** ![Zsyh2619](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/zsyh2619/32/4925_2.png) [@Zsyh2619](https://forum.mattermost.com/u/Zsyh2619)\
**Post date:** [July 7, 2021, 3:25am UTC](https://forum.mattermost.com/t/elasticsearch-is-not-used/11894/3 "2021-07-07T03:25:32Z")

</div>

Ok, I import the messages by the command `mattermost import bulk posts.json --apply`, it took about five hours to do this. Then I click the “Index Now” button. When the index success I can find all the data in elasticsearch. But when I search the history I got 504 in browser console.  
Sorry, I can’t provide any screenshots for the moment. I changed the version to v5.20.0 yesterday. There is no elasticsearch problem in this version. I can repeat this problem later with v5.36.1.  
About the message change to the content in Mysql the fastest test method is `truncate table Posts;`, Then refresh the page and you will find that all the messages are gone

---

<div class="post-metadata">

**Author:** ![ahmaddanial](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ahmaddanial/32/2938_2.png) [@ahmaddanial](https://forum.mattermost.com/u/ahmaddanial)\
**Post date:** [July 9, 2021, 2:29am UTC](https://forum.mattermost.com/t/elasticsearch-is-not-used/11894/4 "2021-07-09T02:29:51Z")

</div>

Hi, @Zsyh2619

Did you purge the indexes first before clicking the index not button based on the changelog entry [here](https://docs.mattermost.com/administration/changelog.html#id113):

> - In v5.26, Elasticsearch indexes needed to be recreated. Admins should re-index Elasticsearch using the **Purge index** and then **Index now** button so that all the changes will be included in the index. Systems may be left with a limited search during the indexing, so it should be done during a time when there is little to no activity because it may take several hours.

I went through the rest of the changelog and could not find any specific breaking changes in between version 5.20.0 and 5.36.1 since you mentioned that it works in the earlier version. So, just trying to understand this further before I escalate this internally.

Also, may I know the reason behind running the `TRUNCATE table` command? As far as I know it deletes the content of the table but not the table itself. Were you importing the 5 million messages to an **existing** Mattermost installation that was running on different versions compared to the origin?

---

<div class="post-metadata">

**Author:** ![Zsyh2619](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/zsyh2619/32/4925_2.png) [@Zsyh2619](https://forum.mattermost.com/u/Zsyh2619)\
**Post date:** [July 9, 2021, 3:22am UTC](https://forum.mattermost.com/t/elasticsearch-is-not-used/11894/5 "2021-07-09T03:22:39Z")

</div>

I deployed in a new virtual machine. There is no data in elasticsearch and mysql.I run this command mainly to verify whether the search is still using mysql. I guess if the search does not use mysql, deleting the data in MySQL should not affect the search results.Now we are testing v5.20.0, I have imported 5 million data, and the query has not encountered any problems.  
I read part of the source code, I think the problem may be in [mattermost-server/server.go at master · mattermost/mattermost-server · GitHub](https://github.com/mattermost/mattermost-server/blob/master/app/server.go#L360) ，I don’t understand why s. sqlstore is used here.

---

<div class="post-metadata">

**Author:** ![amy.blais](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/amy.blais/32/7481_2.png) [@amy.blais](https://forum.mattermost.com/u/amy.blais)\
**Post date:** [July 12, 2021, 6:52pm UTC](https://forum.mattermost.com/t/elasticsearch-is-not-used/11894/6 "2021-07-12T18:52:38Z")

</div>

@ahmaddanial Do we need devs to take a look?

---

<div class="post-metadata">

**Author:** ![ahmaddanial](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ahmaddanial/32/2938_2.png) [@ahmaddanial](https://forum.mattermost.com/u/ahmaddanial)\
**Post date:** [July 18, 2021, 9:59pm UTC](https://forum.mattermost.com/t/elasticsearch-is-not-used/11894/7 "2021-07-18T21:59:42Z")

</div>

Hi, @Zsyh2619 @amy.blais

Sorry for the delayed response. I was on PTO for a bit.

Yes, please. I think it is best for the devs to look into this issue for us to understand the reason behind this issue.
