Search CouchDB Using ElasticSearch River - search

I've created a couchDB river (from this elasticsearch example) for elasticsearch with the following code:
curl -XPUT 'localhost:9200/_river/tasks/_meta' -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "tasks",
"filter" : null
},
"index" : {
"index" : "tasks",
"type" : "tasks",
"bulk_size" : "100",
"bulk_timeout" : "10ms"
}
}'
When I try to search the the couchDB using elasticsearch with this command:
curl -XGET http://localhost:9200/tasks/tasks -d query{"user":"jbattle"}
I get the response:
No handler found for uri [/tasks/tasks] and method [GET][]
I've been searching but have yet to discover a solution to/for this issue.
UPDATE:
I've discovered the proper query is:
curl -XGET 'http://localhost:9200/_river/tasks/_search?q=user:jbattle&pretty=true'
Though, despite no longer receiving an error, I get 0 hits:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}

Both of your queries are incorrect. The first one is missing the endpoint /_search and the second one is querying index _river instead of index tasks.
The _river index is where your river is stored not your data. When you configured your river, you specified index tasks.
So try this instead:
curl -XGET 'http://localhost:9200/tasks/tasks/_search?q=user:jbattle&pretty=true'
Or if that doesn't work, try searching for any docs in tasks/tasks:
curl -XGET 'http://localhost:9200/tasks/tasks/_search?q=*&pretty=true'
clint

The example file you posted got moved to github. These guys give a decent walkthrough of getting couch and elasticsearch to work together.
Unfortunately, the currently accepted answer doesn't work for me. But if I paste something like this in my browser's address bar it works. Notice that there is only one reference to the "tasks" index in the url, not two.
http://localhost:9200/tasks/_search?pretty=true
To do a real search you could try something like this:
http://localhost:9200/tasks/_search?q="hello"&pretty=true

Related

NodeBB - Post Reputation/Likes - Find which users liked a post

I am not able to find where does NodeBB stores the list of users who liked a particular post.
For example, consider following data structure:-
> db.objects.find({_key:"post:2341"}).pretty()
{
"_id" : ObjectId("5547af3f65190fe2122d0b3c"),
"_key" : "post:2341",
"edited" : 0,
"pid" : 2341,
"content" : "content of this post",
"tid" : 2543,
"timestamp" : 1412304172707,
"deleted" : 0,
"editor" : "",
"uid" : 747,
"toPid" : 19999,
"votes" : 0,
"reputation" : 5
}
The above says that Post ID 2341 has 5 reputations which means it is liked by 5 users. But where does it stores that these are the User IDs who liked this particular post?
Finally hunted down for the exact key that stores it in the database via going through NodeBB code. And the particular key that stores it is pid:{postid}:upvote. So we query like this:-
>db.objects.find({_key: "pid:2341:upvote"})
{
"_id": ObjectId("5547af3f65190fe2122d0b3c"),
"_key": "pid:2341:upvote",
"members": ["663", "230", "549"]
}
The above response contains the IDs of the users who upvoted a particular post.

running elasticsearch queries on linux

What 's the correct way of running elasticsearch queries on linux? I came up with the code below but it seems that it is not correct because of many errors that I see.
curl -X GET http://localhost:9200/INDEXED_REPOSITORY/_search?q="constant_score" : {"filter" : { "terms" : { "description" : ["heart", "cancer", and more than 10000 keywords ]}}}}
You're missing a few things, do it like this:
curl -X GET http://localhost:9200/INDEXED_REPOSITORY/_search -d '{
"query": {
"constant_score": {
"filter" : {
"terms" : {
"description" : ["heart", "cancer", and more than 10000 keywords ]
}
}
}
}
}'
or on a single line:
curl -X GET http://localhost:9200/INDEXED_REPOSITORY/_search -d '{"query": {"constant_score": {"filter" : {"terms" : {"description" : ["heart", "cancer", and more than 10000 keywords ]}}}}}'

Mongodb query slow response time

I'm working on a project that uses flexible schemas. I've setup a local mongodb server and am using mongoose inside node.
Having an interesting scaling problem and was wondering if these response times were normal. If a query returns 50 documents, I takes 5-10 seconds for mongo to respond. In the same collection, a query that returns 2 documents is milliseconds.
It's not a slow connection because it's local, was wondering if anyone had an idea as to what was causing this.
I'm using OS X and mongo 3.0.1
Edit: The documents are nearly empty at the moment, with just one or two properties.
Edit: The total number of documents doesn't really matter, just the returned size. If there are 51 documents, 50 like {_id: "...", _schema:"bar"} and 1 {_id:"...", _schema: "foobar" } then collection.find({_schema:"bar"}) takes several seconds and collection.find({_schema:"foobar"}) takes no time.
Explain output:
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "mean-dev.documentmodels",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [ ]
},
"winningPlan" : {
"stage" : "COLLSCAN",
"filter" : {
"$and" : [ ]
},
"direction" : "forward"
},
"rejectedPlans" : [ ]
},
"serverInfo" : {
"host" : "Sams-MBP.local",
"port" : 27017,
"version" : "3.0.1",
"gitVersion" : "nogitversion"
},
"ok" : 1
No, it should not take that much time.
The issue is probably in the operations in your query (projections, sorting, geosearch, grouping, etc). The best way to solve that is by creating an index to speed up such query.
To create an index on _schema field execute that command in mongodb:
db.collection.ensureIndex({"_schema":1});

ElasticSearch and Couchdb view

New to the whole ElasticSearch and couchDB setup. Just got a river going from ES to a db I have in couchDB. If I have a view in a db is there a way to just index that view? For example I have a db named "Movies" and a view called "Action" and another called "byActor".
I was thinking that I could do an index and point it to that, like below, but that doesn't seem to work.
{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "Movies",
"filter" : null
},
"index" : {
"index" : "Action",
"bulk_size" : "100",
"bulk_timeout" : "10ms"
}
}
I think I may not understand what index is exactly because when I run http://localhost:9200/Movies/Action/_search?pretty=true nothing is returned.
Edit: In looking around more it's seeming like this isn't the way to do this. Index just seems to be the way ES indexes? Anyways, I'm reading that mapping might accomplish this. Is that true?
Indexing views is not yet in CouchDb River. See this pull request.

updating nested document with mongoDb + nodeJs

I have a structure like this:
{
"_id" : ObjectId("501abaa341021dc3a1d0c70c"),
"name" : "prova",
"idDj" : "1",
"list" : [
{
"id" : 1,
"votes" : 2
},
{
"id" : 2,
"votes" : 4
}
]
}
And I'm trying to increase votes with this query:
session_collection.update(
{'_id':session_collection.db.bson_serializer.ObjectID.createFromHexString(idSession),'list.id':idSong},
{$inc:{'list.$.votes':1}},
{safe: true} ,
callback);
But it doesn't work, there are no problems it just doesn't update anything.
I think it's because the ['] (simple quotation mark) on the 'list.id' and 'list.$.votes' because the same query inside the terminal works perfectly.
Thanks!
I suspect your matching is not working as you expect. The callback will return
function(err, numberofItemsUpdated, wholeUpdateObject)
numberofItemsUpdated should equal 1 if your matching worked. you'll need to check if idSession and idSong are what you think they are.

Resources