Repository: readthedocs/readthedocs.org

Issue:
Upgrade elastic search to 7.x
https://www.elastic.co/blog/elasticsearch-7-0-0-released

Changelog https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html


Discussion:
We are using [django-elasticsearch-dsl](https://github.com/sabricot/django-elasticsearch-dsl) and unfortunately it is not actively maintained (last commit was on 8th Nov 2018).

What should we do in this case? I can see three options.
* Wait for the update of `django-elasticsearch-dsl`.
* Find another library.
* Switch to only using official low-level library (elasticsearch-py), which is updated, but this involves lot of work.

Edit: `django-elasticsearch-dsl` is updated. :tada:
Just a note.
My elasticsearch version is:
```
$ curl localhost:9200
{
  "name" : "j9iyXmN",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "b4kGzEhFSoiZufVXVlERfg",
  "version" : {
    "number" : "6.7.1",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "2f32220",
    "build_date" : "2019-04-02T15:59:27.961366Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
```

And all the tests pass.
To execute the elastic search tests, you need to pass an extra option to tox
`tox -r -e py36 --including-search`
@stsewd 
Yes... I am aware of that.
All tests are passing including the search tests. :smile: 
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@dojutsu-user is there anything actionable on this issue now? I'm not sure, but I think it's not possible to upgrade now. In that case, we should add why it's not possible to upgrade and what are the problems here to track them, and propose a plan --or close it, instead of having it open without adding value.
@humitos 
I don't think upgradation should pose any problems.
During the whole gsoc period, I have been using Elasticsearch 6.7
```
$ curl localhost:9200
{
  "name" : "j9iyXmN",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "b4kGzEhFSoiZufVXVlERfg",
  "version" : {
    "number" : "6.7.2",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "56c6e48",
    "build_date" : "2019-04-29T09:05:50.290371Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
```

I just read the `django-elasticsearch-dsl` is going to have a new release pretty soon -- https://github.com/sabricot/django-elasticsearch-dsl/issues/177#issuecomment-509733539 (But not for ES version 7)
I think we have to wait for few days until django-elasticsearch-dsl starts supporting ES v7
This is blocked on https://github.com/sabricot/django-elasticsearch-dsl/issues/170
I am unblocking this as https://github.com/sabricot/django-elasticsearch-dsl/issues/170 is closed and django-elasticsearch-dsl is supporting elasticsearch version 7 (https://pypi.org/project/django-elasticsearch-dsl/)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

We received an email from ES that we need to migrate to a recent version, since 6.x is EOL, this isn't low priority anymore.
Just checked, we are running `v6.5.4` in production, we need to update to `6.8.12` before updating to a mayor version.
Changelog for 6.6, 6.7 and 6.8

- https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.6.html
- https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.7.html
- https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.8.html

We are good to upgrade from 6.5 to 6.8. And we don't need a re-index or downtime.

>  Migration between minor versions — e.g. 6.x to 6.y — can be performed by upgrading one node at a time. 

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes.html

> A rolling upgrade allows an Elasticsearch cluster to be upgraded one node at a time so upgrading does not interrupt service.

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/rolling-upgrades.html

Resolving patch:
diff --git a/readthedocs/search/faceted_search.py b/readthedocs/search/faceted_search.py
--- a/readthedocs/search/faceted_search.py
+++ b/readthedocs/search/faceted_search.py
@@ -275,7 +275,7 @@ def total_count(self):
         # we are only interested in the total count
         s = s.extra(size=0)
         s = s.execute()
-        return s.hits.total
+        return s.hits.total['value']
 
     def query(self, search, query):
         """


Test patch: