# ElasticSearch and Mongo DB

**URL:** https://discuss.elastic.co/t/elasticsearch-and-mongo-db/11571
**Category:** Elasticsearch
**Created:** [April 13, 2013, 11:45am UTC](https://discuss.elastic.co/t/elasticsearch-and-mongo-db/11571 "2013-04-13T11:45:21Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Vadim\_Bartko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vadim_bartko/32/2397_2.png) [@Vadim\_Bartko](https://discuss.elastic.co/u/Vadim_Bartko)
#### Post date: [April 13, 2013, 11:45am UTC](https://discuss.elastic.co/t/elasticsearch-and-mongo-db/11571/1 "2013-04-13T11:45:21Z")

</div>

Hi,

I am trying to connect MongoDB to ES via river. My steps:  
1.Install mongo.  
2. edit /etc/mongodb.conf, add replSet=rs0 record.  
3.Install ES  
4.Install elasticsearch-river-mongodb driver  
5.curl -XPUT '[http://localhost:9200/\_river/mongodb/\_meta](http://localhost:9200/_river/mongodb/_meta)' -d '{

```
"type": "mongodb", 
"mongodb": { 
    "db": "testmongo", 
    "collection": "person"
}, 
"index": {
    "name": "mongoindex", 
    "type": "person" 
}

```

}'

6.Add some data

use testmongo  
var p = {firstName: "John", lastName: "Doe"}  
db.person.save(p)

7.Query

curl -XGET '[http://localhost:9200/testmongo/\_search?q=firstName:John](http://localhost:9200/testmongo/_search?q=firstName:John)'

Response:  
{"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":[]}}

The same true is for pdf files (with attachment plugins). I can't data  
indexed at all. What am I missing?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Vadim\_Bartko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vadim_bartko/32/2397_2.png) [@Vadim\_Bartko](https://discuss.elastic.co/u/Vadim_Bartko)
#### Post date: [April 13, 2013, 11:59am UTC](https://discuss.elastic.co/t/elasticsearch-and-mongo-db/11571/2 "2013-04-13T11:59:01Z")

</div>

Update:  
I can get results using  
curl -XGET "localhost:9200/\_search?q=firstName:John&pretty=true" (without  
index)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [April 13, 2013, 12:00pm UTC](https://discuss.elastic.co/t/elasticsearch-and-mongo-db/11571/3 "2013-04-13T12:00:59Z")

</div>

Hey,

you configured the index to write into as "mongoindex" if you use the above  
configuration. So you need to specify that index to query and not the mongo  
db name...

On Sat, Apr 13, 2013 at 1:45 PM, Vadim Bartko [hudvin@gmail.com](mailto:hudvin@gmail.com) wrote:

> Hi,
> 
> I am trying to connect MongoDB to ES via river. My steps:  
> 1.Install mongo.  
> 2. edit /etc/mongodb.conf, add replSet=rs0 record.  
> 3.Install ES  
> 4.Install elasticsearch-river-mongodb driver  
> 5.curl -XPUT '[http://localhost:9200/\_river/mongodb/\_meta](http://localhost:9200/_river/mongodb/_meta)' -d '{
> 
> ```
> "type": "mongodb",
> "mongodb": {
> "db": "testmongo",
> "collection": "person"
> },
> "index": {
> "name": "mongoindex",
> "type": "person"
> }
> 
> ```
> 
> }'
> 
> 6.Add some data
> 
> use testmongo  
> var p = {firstName: "John", lastName: "Doe"}  
> db.person.save(p)
> 
> 7.Query
> 
> curl -XGET '[http://localhost:9200/testmongo/\_search?q=firstName:John](http://localhost:9200/testmongo/_search?q=firstName:John)'
> 
> Response:
> 
> {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> The same true is for pdf files (with attachment plugins). I can't data  
> indexed at all. What am I missing?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Vadim\_Bartko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vadim_bartko/32/2397_2.png) [@Vadim\_Bartko](https://discuss.elastic.co/u/Vadim_Bartko)
#### Post date: [April 14, 2013, 1:16pm UTC](https://discuss.elastic.co/t/elasticsearch-and-mongo-db/11571/4 "2013-04-14T13:16:30Z")

</div>

Thanks, it works!  
Now I am trying to get highlights to for indexed pdfs.

I use this example:

curl -XPUT '[http://localhost:9200/\_river/mongodb/\_meta](http://localhost:9200/_river/mongodb/_meta)' -d '{  
"type": "mongodb",  
"mongodb": {  
"db": "testmongo",  
"collection": "fs",  
"gridfs": true  
},  
"index": {  
"name": "mongoindex",  
"type": "files"  
}  
}'

put to file to mongo:

mongofiles --host localhost:27017 --db testmongo --collection fs --type  
applicaton/pdf put ~/Downloads/papers/fulltefffxt.pdf

I am able to get relevant results, but content always returned as base64  
string. Should I change somehow mapping to store:yes? I have been playing  
with different settings, but without any success.

On Saturday, 13 April 2013 08:00:59 UTC-4, Alexander Reelsen wrote:

> Hey,
> 
> you configured the index to write into as "mongoindex" if you use the  
> above configuration. So you need to specify that index to query and not the  
> mongo db name...
> 
> On Sat, Apr 13, 2013 at 1:45 PM, Vadim Bartko \<[hud...@gmail.com](mailto:hud...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > I am trying to connect MongoDB to ES via river. My steps:  
> > 1.Install mongo.  
> > 2. edit /etc/mongodb.conf, add replSet=rs0 record.  
> > 3.Install ES  
> > 4.Install elasticsearch-river-mongodb driver  
> > 5.curl -XPUT '[http://localhost:9200/\_river/mongodb/\_meta](http://localhost:9200/_river/mongodb/_meta)' -d '{
> > 
> > ```
> > "type": "mongodb", 
> > "mongodb": { 
> > "db": "testmongo", 
> > "collection": "person"
> > }, 
> > "index": {
> > "name": "mongoindex", 
> > "type": "person" 
> > }
> > 
> > ```
> > 
> > }'
> > 
> > 6.Add some data
> > 
> > use testmongo  
> > var p = {firstName: "John", lastName: "Doe"}  
> > db.person.save(p)
> > 
> > 7.Query
> > 
> > curl -XGET '[http://localhost:9200/testmongo/\_search?q=firstName:John](http://localhost:9200/testmongo/_search?q=firstName:John)'
> > 
> > Response:
> > 
> > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> > 
> > The same true is for pdf files (with attachment plugins). I can't data  
> > indexed at all. What am I missing?
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Vadim\_Bartko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vadim_bartko/32/2397_2.png) [@Vadim\_Bartko](https://discuss.elastic.co/u/Vadim_Bartko)
#### Post date: [April 14, 2013, 4:38pm UTC](https://discuss.elastic.co/t/elasticsearch-and-mongo-db/11571/5 "2013-04-14T16:38:20Z")

</div>

I found correct mappind:

curl -XPUT '[http://localhost:9200/mongoindex/files/\_mapping](http://localhost:9200/mongoindex/files/_mapping)' -d '{  
"files": {  
"properties": {  
"content": {  
"path": "full",  
"type": "attachment",  
"fields": {  
"title" : { "store" : "yes" },  
"file" : { "term\_vector":"with\_positions\_offsets", "store":"yes" },  
"content": {  
"type": "string",  
"term\_vector":"with\_positions\_offsets", "store":"yes"  
},  
"author": {  
"type": "string"  
},  
"keywords": {  
"type": "string"  
},  
"name": {  
"type": "string"  
},  
"date": {  
"format": "dateOptionalTime",  
"type": "date"  
},  
"content\_type": {  
"type": "string"  
}  
},

"chunkSize": {

"type": "long"  
},  
"md5": {  
"type": "string"  
},  
"length": {  
"type": "long"  
},  
"filename": {  
"type": "string"  
},  
"contentType": {  
"type": "string"  
},  
"uploadDate": {  
"format": "dateOptionalTime",  
"type": "date"  
},  
"metadata": {  
"dynamic": "true",  
"type": "object"  
}  
}  
}  
}}'

On Sunday, 14 April 2013 09:16:30 UTC-4, Vadim Bartko wrote:

> Thanks, it works!  
> Now I am trying to get highlights to for indexed pdfs.
> 
> I use this example:
> 
> curl -XPUT '[http://localhost:9200/\_river/mongodb/\_meta](http://localhost:9200/_river/mongodb/_meta)' -d '{  
> "type": "mongodb",  
> "mongodb": {  
> "db": "testmongo",  
> "collection": "fs",  
> "gridfs": true  
> },  
> "index": {  
> "name": "mongoindex",  
> "type": "files"  
> }  
> }'
> 
> put to file to mongo:
> 
> mongofiles --host localhost:27017 --db testmongo --collection fs --type  
> applicaton/pdf put ~/Downloads/papers/fulltefffxt.pdf
> 
> I am able to get relevant results, but content always returned as base64  
> string. Should I change somehow mapping to store:yes? I have been playing  
> with different settings, but without any success.
> 
> On Saturday, 13 April 2013 08:00:59 UTC-4, Alexander Reelsen wrote:
> 
> > Hey,
> > 
> > you configured the index to write into as "mongoindex" if you use the  
> > above configuration. So you need to specify that index to query and not the  
> > mongo db name...
> > 
> > On Sat, Apr 13, 2013 at 1:45 PM, Vadim Bartko [hud...@gmail.com](mailto:hud...@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I am trying to connect MongoDB to ES via river. My steps:  
> > > 1.Install mongo.  
> > > 2. edit /etc/mongodb.conf, add replSet=rs0 record.  
> > > 3.Install ES  
> > > 4.Install elasticsearch-river-mongodb driver  
> > > 5.curl -XPUT '[http://localhost:9200/\_river/mongodb/\_meta](http://localhost:9200/_river/mongodb/_meta)' -d '{
> > > 
> > > ```
> > > "type": "mongodb", 
> > > "mongodb": { 
> > > "db": "testmongo", 
> > > "collection": "person"
> > > }, 
> > > "index": {
> > > "name": "mongoindex", 
> > > "type": "person" 
> > > }
> > > 
> > > ```
> > > 
> > > }'
> > > 
> > > 6.Add some data
> > > 
> > > use testmongo  
> > > var p = {firstName: "John", lastName: "Doe"}  
> > > db.person.save(p)
> > > 
> > > 7.Query
> > > 
> > > curl -XGET '[http://localhost:9200/testmongo/\_search?q=firstName:John](http://localhost:9200/testmongo/_search?q=firstName:John)'
> > > 
> > > Response:
> > > 
> > > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> > > 
> > > The same true is for pdf files (with attachment plugins). I can't data  
> > > indexed at all. What am I missing?
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [July 6, 2017, 2:41am UTC](https://discuss.elastic.co/t/elasticsearch-and-mongo-db/11571/6 "2017-07-06T02:41:12Z")

</div>


