Node.js 如何使用elasticsearchclient搜索内部数组
我已经安装了elasticsearch river couchdb和节点elasticsearchclient。现在我正在使用node elasticsearchclient在couchdb中搜索数据。我有这样的JSON结构Node.js 如何使用elasticsearchclient搜索内部数组,node.js,couchdb,elasticsearch,Node.js,Couchdb,elasticsearch,我已经安装了elasticsearch river couchdb和节点elasticsearchclient。现在我正在使用node elasticsearchclient在couchdb中搜索数据。我有这样的JSON结构 { first_name: "aruna", interests: [ {name: "pets", level: 5}, {topic: "es", degree: "strong"}
{
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,那个么我就能够得到完整的文档。但是当我搜索宠物或强壮或5或es时,我没有得到文档。任何人都可以帮助解决这个问题。我没有使用node,但是一旦我使用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}
我可以使用查询字符串搜索字符串宠物:
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_字符串的嵌套字段,具体情况如下:
兴趣爱好:宠物