Skip to content

Fix Elasticsearch indexes/rivers in local dev Docker container (search)

Currently the Elasticsearch indexes and rivers in the local dev Docker webapp_elasticsearch_1 container do not work. Elasticsearch drivers search for rooms, messages, users

http://localhost:9200/_plugin/head/

http://localhost:9200/_plugin/river-mongodb/

Dev notes

Diving into the Elasticsearch container, it can access mongo1 which is linked in the Docker compose config

$ docker exec -it webapp_elasticsearch_1 /bin/bash
$ curl mongo1:27017
It looks like you are trying to access MongoDB over HTTP on the native driver port.

More logging

Add some elasticsearch-river-mongodb log tracing (via https://github.com/richardwilly98/elasticsearch-river-mongodb/wiki#troubleshooting)

Add the config

Commands to add config
$ docker exec -it webapp_elasticsearch_1 /bin/bash

$ cat << 'EOF' > /usr/share/elasticsearch/config/logging.yml
rootLogger: INFO,console
logger:
  river.mongodb: TRACE
  rest.action: TRACE
  org.elasticsearch.river.mongodb: TRACE

appender:
  console:
    type: console
    layout:
      type: consolePattern
      conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
EOF

View the logs:

$ docker exec -it webapp_elasticsearch_1 /bin/bash
$ cat /data/es/logs/es-command-output.log

Does Mongo have a replica set/oplog?

The elasticsearch-river-mongodb wiki says to "Make sure to enable replica set".

Seems like it is working

$ mongo gitter
> use local
> db.oplog.rs.count()
313148
> rs.printReplicationInfo()
configured oplog size:   1978.281982421875MB
log length start to end: 43687232secs (12135.34hrs)
oplog first event time:  Thu Oct 01 2020 04:07:09 GMT+0000 (UTC)
oplog last event time:   Fri Feb 18 2022 19:27:41 GMT+0000 (UTC)
now:                     Fri Feb 18 2022 19:27:44 GMT+0000 (UTC)
> db.getReplicationInfo()
{
        "logSizeMB" : 1978.281982421875,
        "usedMB" : 66.43,
        "timeDiff" : 43687232,
        "timeDiffHours" : 12135.34,
        "tFirst" : "Thu Oct 01 2020 04:07:09 GMT+0000 (UTC)",
        "tLast" : "Fri Feb 18 2022 19:27:41 GMT+0000 (UTC)",
        "now" : "Fri Feb 18 2022 19:27:55 GMT+0000 (UTC)"
}
> rs.status()
{
        "set" : "troupeSet",
        "date" : ISODate("2022-02-18T20:28:24.704Z"),
        "myState" : 1,
        "term" : NumberLong(43),
        "heartbeatIntervalMillis" : NumberLong(2000),
        "members" : [
                {
                        "_id" : 0,
                        "name" : "127.0.0.1:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 1628737,
                        "optime" : {
                                "ts" : Timestamp(1645214524, 9),
                                "t" : NumberLong(43)
                        },
                        "optimeDate" : ISODate("2022-02-18T20:02:04Z"),
                        "electionTime" : Timestamp(1643587368, 1),
                        "electionDate" : ISODate("2022-01-31T00:02:48Z"),
                        "configVersion" : 1,
                        "self" : true
                }
        ],
        "ok" : 1
}
Edited by Eric Eastwood