0

我已经安装了 elasticsearch-river-couchdb 和 node elasticsearchclient。现在我正在使用 node elasticsearchclient 在 couchdb 中搜索数据。我有这样的JSON结构,

{   
    first_name: "aruna", 
    interests: [ {name: "pets", level: 5}, 
                 {topic: "es", degree: "strong"}
              ] ,
designation: "SE",
company: "DOM",
salary: 200000
}

现在我需要搜索我在查询中给出的任何值。为此,我尝试了以下代码,

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()
}

如果我将 searchText 的值设为 aruna 或 SE 或 DOM 或 200000,我就能获得完整的文档。但是当我搜索pets或strong或5或es时,我没有得到文件。请任何人都可以帮助解决这个问题。

4

1 回答 1

0

我没有使用节点,但是一旦我使用 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}

我可以使用 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
}

注意:当您在字段内创建带有哈希的索引时,它称为嵌套索引,我不确定通配符查询查询嵌套字段。但是查询字符串可以。同样在 19.4 中,您可以使用特殊语法查询带有 query_string 的嵌套字段,在您的情况下:interests.*:pets

http://www.elasticsearch.org/blog/2012/05/21/0.19.4-released.html

于 2012-06-22T22:16:02.150 回答