elasticsearch中如何根据createdDate等字段进行搜索
How to search based on createdDate and other fields in elastic search
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"
}
}
}
}
})
我想搜索 client name 和 createddate 等多个字段。我在正文部分传递了这些字段。
It returns an error. Please help me where I am doing wrong. Thanks!
您需要使用 bool/must/filter
:
组合两个约束
client.search({
index: 'allevents_production',
"body": {
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "clientname",
"query": "ser"
}
}
],
"filter": [
{
"range": {
"createddate": {
"gte": "now-1d/d",
"lt": "now/d"
}
}
}
]
}
}
}
})
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"
}
}
}
}
})
我想搜索 client name 和 createddate 等多个字段。我在正文部分传递了这些字段。
It returns an error. Please help me where I am doing wrong. Thanks!
您需要使用 bool/must/filter
:
client.search({
index: 'allevents_production',
"body": {
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "clientname",
"query": "ser"
}
}
],
"filter": [
{
"range": {
"createddate": {
"gte": "now-1d/d",
"lt": "now/d"
}
}
}
]
}
}
}
})