- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Node js 在 Elasticsearch 中进行搜索。这是我的脚本
var elasticsearch = require('elasticsearch');
var client = elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: Infinity,
// undocumented params are appended to the query string
hello: "elasticsearch!"
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well');
getmeres(client);
}
});
function getmeres(client)
{
client.search({
index: 'researchtest',
body: {
"aggs": {
"docs": {
"terms": {
"field": "DocumentID",
"size": 0
}
}
}
}
}, function (error, response) {
if (error) {
console.trace('Search query failed');
} else {
console.log('All is well');
d=response;//console.log(response);
showdocs(d)
}
});
}
function showdocs(d){
console.log(d["hits"]);}
我明白了
All is well
{ total: 92,
max_score: 1,
hits:
[ { _index: 'researchtest',
_type: 'test',
_id: 'AVLC2axzrLgN-DZLLsmp',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2izQrLgN-DZLLsnw',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2EEnrLgN-DZLLsjj',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2F7MrLgN-DZLLsj6',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2nhDrLgN-DZLLsol',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2pMUrLgN-DZLLsox',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2mTMrLgN-DZLLsoL',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2rDZrLgN-DZLLspS',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2t5ErLgN-DZLLsp8',
_score: 1,
_source: [Object] },
{ _index: 'researchtest',
_type: 'test',
_id: 'AVLC2dVHrLgN-DZLLsnA',
_score: 1,
_source: [Object] } ] }
但我在这里看不到我想要的实际值。我如何从响应中获取值?在控制台中我也看到了
"aggregations": {
"docs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "2235",
"doc_count": 2
},
{
"key": "12312",
"doc_count": 2
},
{
"key": "4565",
"doc_count": 2
},
{
"key": "7809780",
"doc_count": 2
},
{
"key": "8678",
"doc_count": 2
},
然后它继续列出所有匹配的结果
我只想要唯一值,我应该如何为其指定聚合?
在这种情况下,如何从上述查询的结果中提取实际值或键
?
编辑
所以我有点明白了。我可以访问
function showdocs(d){
da=d.hits.hits
for (i=0;i<da.length;i++)
{
console.log(da[i]["_source"]["DocumentID"]);}}
但这只会返回 10 个结果!我确定我在那个领域有 50 个不同的值
最佳答案
使用大小为0的聚合桶,
"body": {
"size": 0,
"aggs": {
"docs": {
"terms": {
"field": "DocumentID",
"size": 10 // if you want 50 make it 50
}
}
}
}
关于javascript - Elasticsearch NodeJS 搜索 : How to retrieve results from response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35342899/
我有一条路线,有两个与之关联的模型,如下所示: App.IndexRoute = Ember.Route.extend({ model: function() { return Emb
这是我的第一个 Python 脚本,所以我认为我做错了什么。但是我在任何教程或示例中都找不到线索。以下代码(可以这么说): import urllib urllib.retrieve("http://
SDK:适用于 Go 0.5.0 的 Apache Beam SDK 我们在 Google Cloud Data Flow 中运行 Apache Beam Go SDK 作业。他们一直工作得很好,直到
我希望简化网站用户在 Adobe Business Catalyst 网站上注册、登录和检索/重置密码的流程。 我已成功使用 AJAX 提交安全区登录表单。我还使用 jQuery.load 从密码
我在 R 中收到以下错误消息: Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set", : Unable to r
在什么情况下“反文档频率”在信息检索中不起作用? 最佳答案 如果您不希望在系统中权衡稀有术语而不是频繁出现的术语,则可能不希望使用IDF。此外,计算idf是一项昂贵的操作。从以下事实可以明显看出这一点
我正在尝试计算 Average Precision (和 Mean Average Precision )在 Oxford Building image dataset 上. 下面是他们提供的用于计算
有人知道在网站上查找最相关的联系信息的脚本/食谱/库吗? 一些可能的情况: 在个人网页上查找联系电话号码 在博客上查找所有者电子邮件地址 查找联系页面的网址 最佳答案 查看WSO2's Mashup
我看过像“sc2ranks.com”这样的网站,我完全想知道他们是如何获得我只能在游戏中访问的信息的。我的意思是我如何访问星际争霸 II 欧盟天梯?这只是我们必须访问/下载的 URL,还是需要通过注入
我已阅读 Permuterm indexes stanford 网站上的页面,但是我仍然无法弄清楚我们如何从以下地址到达:*X*至 X* . 那么$在哪里? ? 我可以得到这些: For X, loo
考虑以下选定的 html 片段: .......... .......||||||||||||||||||||||||||||||....... 第二行代表用户选择(管道),跨越多个跨度标签。使用 j
我需要从我的 GitHub 私有(private)仓库下载一个文件。因此,按照 GitHub 站点上的说明,我为我的凭据创建了一个 OAuth token 。 然后我执行了这个 PS 脚本: $Web
我有几个扩展 C 的类,并且我需要一个接受 C 类型的任何参数的方法。但是在这个方法中我想知道我正在处理 A 还是 B。 * public A extends C public B extends C
我正在尝试学习 Apache Struts 框架,并且我编写了一个用于进行类(class)注册的小型应用程序,但每当我尝试加载我的应用程序时,它都会抛出以下异常: javax.servlet.Serv
有点跟进 my self-answered question about finding the column names. 在 UniVerse 中,您无法查询文件的所有列,除非文件字典中的 @ 短
我正在为 Dynamics CRM 2011 创建一个插件,以便在用户打开潜在客户时执行。所以我使用 Retrieve 消息来执行插件。 IPluginExecutionContext context
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
正在尝试检索文章的文本。我想选择 中的所有文本 ... 我做到了。 但我只想从文章正文中检索文本,而不是整个页面 Document article = Jsoup.connect("html doc
我一直在尝试元素存储,但我被元素存储中的 .retrieve(); 问题所困扰。 文档指出: Element:retrieve actually accepts an optional second
尝试对 facebook 进行图形 API 调用时出现以下错误。我知道我的回调 url 很好,因为当我在 facebook 调试器中测试它时,它可以很好地查看页面。我也在使用 Google App E
我是一名优秀的程序员,十分优秀!