I have installed elasticsearch-river-couchdb and node elasticsearchclient. Now i am searching data in couchdb using node elasticsearchclient. I have JSON structure like this,
{
first_name: "aruna",
interests: [ {name: "pets", level: 5},
{topic: "es", degree: "strong"}
] ,
designation: "SE",
company: "DOM",
salary: 200000
}
Now i need to search whatever value i have given in the query. For that i tried the below code,
var searchText = '*aru*'
testSearch = function() {
var qryObj = {
"size" : 50,
"query" : {
"wildcard" : {
"_all" :searchText
}
}
};
elasticSearchClient.search("test", "",qryObj, size)
.on('data', function(data) {
console.log("Search: "+data)
assert.ok(JSON.parse(data), "testSearch failed.")
})
.exec()
}
If I give value for searchText as aruna or SE or DOM or 200000, I am able to get complete document. But when i search for pets or strong or 5 or es, i didnt get the document. Please anyone can help out to solve this.
I'm not using node, however once I created index using curl:
curl -XPOST 'http://localhost:9200/test/contact/' -d '
{
first_name: "aruna",
interests: [ {name: "pets", level: 5},
{topic: "es", degree: "strong"}
] ,
designation: "SE",
company: "DOM",
salary: 200000
}
'
{"ok":true,"_index":"test","_type":"contact","_id":"B1it8B1wTqGkx3qSQqSo1Q","_version":1}
I can search for string pets using query_string:
curl -XGET http://localhost:9200/test/contact/_search -d '
{"query":{"bool":{"must":[{"query_string": {"default_field":"_all","query":"pets"}}],"must_not":[],"should": []}},"from":0,"size":50,"sort":[],"facets":{}}
'
{"took":3,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits": {"total":1,"max_score":0.06780553,"hits": [{"_index":"test","_type":"contact","_id":"B1it8B1wTqGkx3qSQqSo1Q","_score":0.06780553, "_source" :
{
first_name: "aruna",
interests: [ {name: "pets", level: 5},
{topic: "es", degree: "strong"}
] ,
designation: "SE",
company: "DOM",
salary: 200000
}
Note: when you are creating index with hash inside the field it is called nested index and i'm not sure wildcard query queries nested fields. However query string does. Also in 19.4 you can query nested fields with query_string using special syntax, in your case: interests.*:pets
http://www.elasticsearch.org/blog/2012/05/21/0.19.4-released.html