最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何基于弹性搜索中的createdDate和其他字段进行搜索

IT培训 admin 4浏览 0评论

如何基于弹性搜索中的createdDate和其他字段进行搜索

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
     host: 'ABC',
     log: 'trace'
});

client.search({
index: 'allevents_production',
"body": {
    "query": {
        "query_string": {
            "default_field": "clientname",
            "query": 'ser'
        },
        "range" : {
            "createddate" : {
                "gte" : "now-1d/d",
                "lt" :  "now/d"
            }
        }
    }
}
})

我想搜索多个字段,例如客户端名称创建日期。我在身体部位传递了这些字段。

它返回错误。请帮我哪里做错了。谢谢!

回答如下:

您需要使用bool/must/filter组合两个约束:

bool/must/filter

如何基于弹性搜索中的createdDate和其他字段进行搜索

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
     host: 'ABC',
     log: 'trace'
});

client.search({
index: 'allevents_production',
"body": {
    "query": {
        "query_string": {
            "default_field": "clientname",
            "query": 'ser'
        },
        "range" : {
            "createddate" : {
                "gte" : "now-1d/d",
                "lt" :  "now/d"
            }
        }
    }
}
})

我想搜索多个字段,例如客户端名称创建日期。我在身体部位传递了这些字段。

它返回错误。请帮我哪里做错了。谢谢!

回答如下:

您需要使用bool/must/filter组合两个约束:

bool/must/filter
发布评论

评论列表 (0)

  1. 暂无评论