Skip to content

Commit ffd54ab

Browse files
authored
Merge pull request #4196 from rtfd/rajujha373-elasticsearch-guide
Build on top of #3881 and put docs in custom_installs.
2 parents e9d349c + f42fd65 commit ffd54ab

File tree

2 files changed

+121
-3
lines changed

2 files changed

+121
-3
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
==========================================
2+
Enabling Elasticsearch on the local server
3+
==========================================
4+
5+
Read the Docs has been using Elasticsearch for indexing and searching. To enable this on your local installation, you need to install elasticsearch and run the Elastic server locally.
6+
7+
Installation has been mainly divided into following steps.
8+
9+
Installing Java
10+
---------------
11+
12+
Elasticsearch requires Java 8 or later. Use `Oracle official documentation <http://www.oracle.com/technetwork/java/javase/downloads/index.html>`_.
13+
or opensource distribution like `OpenJDK <http://openjdk.java.net/install/>`_.
14+
15+
After installing java, verify the installation by,::
16+
17+
$ java -version
18+
19+
The result should be something like this::
20+
21+
openjdk version "1.8.0_151"
22+
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
23+
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
24+
25+
26+
Downloading and installing Elasticsearch
27+
----------------------------------------
28+
29+
Elasticsearch can be downloaded directly from elastic.co. For Ubuntu, it's best to use the deb (Debian) package which will install everything you need to run Elasticsearch.
30+
31+
RTD currently uses elasticsearch 1.x which can be easily downloaded and installed from `elastic.co
32+
<https://www.elastic.co/downloads/past-releases/elasticsearch-1-3-8/>`_.
33+
34+
Install the downloaded package by following command::
35+
36+
$ sudo apt install .{path-to-downloaded-file}/elasticsearch-1.3.8.deb
37+
38+
Custom setup
39+
------------
40+
41+
You need the icu plugin::
42+
43+
$ elasticsearch/bin/plugin -install elasticsearch/elasticsearch-analysis-icu/2.3.0
44+
45+
Running Elasticsearch from command line
46+
---------------------------------------
47+
48+
Elasticsearch is not started automatically after installation. How to start and stop Elasticsearch depends on whether your system uses SysV init or systemd (used by newer distributions). You can tell which is being used by running this command::
49+
50+
$ ps -p 1
51+
52+
**Running Elasticsearch with SysV init**
53+
54+
Use the ``update-rc.d command`` to configure Elasticsearch to start automatically when the system boots up::
55+
56+
$ sudo update-rc.d elasticsearch defaults 95 10
57+
58+
Elasticsearch can be started and stopped using the service command::
59+
60+
$ sudo -i service elasticsearch start
61+
$ sudo -i service elasticsearch stop
62+
63+
If Elasticsearch fails to start for any reason, it will print the reason for failure to STDOUT. Log files can be found in /var/log/elasticsearch/.
64+
65+
**Running Elasticsearch with systemd**
66+
67+
To configure Elasticsearch to start automatically when the system boots up, run the following commands::
68+
69+
$ sudo /bin/systemctl daemon-reload
70+
$ sudo /bin/systemctl enable elasticsearch.service
71+
72+
Elasticsearch can be started and stopped as follows::
73+
74+
$ sudo systemctl start elasticsearch.service
75+
$ sudo systemctl stop elasticsearch.service
76+
77+
To verify run::
78+
79+
$ curl http://localhost:9200
80+
81+
82+
You should get something like::
83+
84+
{
85+
status: 200,
86+
name: "Amina Synge",
87+
version: {
88+
number: "1.3.8",
89+
build_hash: "475733ee0837fba18c00c3ee76cd49a08755550c",
90+
build_timestamp: "2015-02-11T14:45:42Z",
91+
build_snapshot: false,
92+
lucene_version: "4.9"
93+
},
94+
tagline: "You Know, for Search"
95+
}
96+
97+
Index the data available at RTD database
98+
----------------------------------------
99+
100+
You need to create the indexes::
101+
102+
from readthedocs.search.indexes import Index, ProjectIndex, PageIndex, SectionIndex
103+
104+
index = Index()
105+
index_name = index.timestamped_index()
106+
index.create_index(index_name)
107+
index.update_aliases(index_name)
108+
# Update mapping
109+
proj = ProjectIndex()
110+
proj.put_mapping()
111+
page = PageIndex()
112+
page.put_mapping()
113+
sec = SectionIndex()
114+
sec.put_mapping()
115+
116+
In order to search through the RTD database, you need to index it into the elasticsearch index::
117+
118+
$ python manage.py reindex_elasticsearch
119+
120+
You are ready to go!

docs/install.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ need to install Python 2.7 with virtualenv in your system as well.
5757
If you want full support for searching inside your Read the Docs
5858
site you will need to install Elasticsearch_.
5959

60-
Ubuntu users could install this package as following::
61-
62-
sudo apt-get install elasticsearch
60+
Ubuntu users could install this package by following :doc:`/custom_installs/elasticsearch`.
6361

6462
.. note::
6563

0 commit comments

Comments
 (0)