ElasticSearch 5.*,查询:字段不存在或存在值是否应为该值
考虑以下停止字段是时间戳字段 我想用以下条件筛选数据:ElasticSearch 5.*,查询:字段不存在或存在值是否应为该值,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,考虑以下停止字段是时间戳字段 我想用以下条件筛选数据: 停止字段不存在 或者,停止字段值为>=now 我知道,我应该用must_,not,但不知道怎么用 我想对子类型进行一些评分,并使用此评分对父项进行排序,然后使用停止字段筛选出父项 GET indexName/parentType/_search { "query": { "bool": { "must": [ { "has_child": { "type":
GET indexName/parentType/_search
{
"query": {
"bool": {
"must": [
{
"has_child": {
"type": "child-type",
"score_mode": "max",
"query": {
"function_score": {
"functions": [
{
"script_score": {
"script": {
"file": "score-analytics",
"lang": "expression"
}
}
}
]
}
}
}
},
{
"bool": {
"should": [
{
"range": {
"stop": {
"gte": "now"
}
}
}
]
}
}
]
}
}
}
您需要使用现有筛选器:
"bool":
{ "should":[
{ "range":
{ "stop":
{ "gte": "now" }
}
},
{ "query":
{ "exists" :
{ "field" : "stop" }
}
}
] }
如果使用,
必须_not
bool
条件,以筛选字段不存在。您的查询可能如下所示:
"query": {
"filtered": {
"filter": {
"bool": {
"must_not": [
{
"exists": {
"field": "stop" <-- give the field which shouldn't exist
}
}
]
}
}
}
}
“查询”:{
“过滤”:{
“过滤器”:{
“布尔”:{
“不得”:[
{
“存在”:{
“field”:“stop”我通过下面的过滤器得到了想要的结果,但仍然在寻找更好的东西。{“bool”:{“should”:[{“range”:{“stop”:{“gte”:“now”}},{“bool”:{“must_not”:[{“exists”:{“field”:“stop”}}}}}}您的评论中的查询正是您需要的查询。您还需要添加“minimum(u should)match”:1