json - Elasticsearch “span and”

标签 json elasticsearch

我有一个elasticsearch查询:

"query": {
    "bool": {
        "minimum_should_match": 1,
        "should": {
            "span_not": {
                "exclude": {
                    "span_or": {
                        "clauses": [{
                            "span_near": {
                              ...
                            },
                            "span_near": {
                              ...
                            }
                        }]
                    }
                }...

我需要在include子句中添加以下内容:
"span_or": {
clauses: [
{
    "span_near": {...}
}
,
{
    "span_and": {
        "clases": [
        {
            "span_near": {...}
        }
        ,
        {
            "span_near": {...}
        }
        ,
        ...
        ]
    }
}
]

}

我的意思是,我有“或”查询:
(span_near or span_near or span_near or ...)

我想得到“和”查询:
(span_near or (span_near and span_near) or ...)

我该怎么做?没有标签“span_and”。我可以改用什么标签?

更新1

我已经试过了:
"span_or": {
                            clauses: [
                            {
                                "span_multi": {
                                    "match": {
                                        "regexp": {
                                            "message": "путин.*"
                                        }
                                    }
                                }
                            }
                            ,
                            {
                                "span_multi": {
                                    "match": {
                                        "bool": {
                                            "must": [
                                                {
                                                    "term" : { "message" : "test" }
                                                },
                                                {
                                                    "term" : { "message" : "rrr" }
                                                }
                                            ]
                                        }
                                    }
                                }
                            }
                            ]
                        }

但我有一个错误:

spanMultiTerm [match] must be of type multi term query

最佳答案

普通的bool查询可以解决您的问题吗?

{
    "query": {
        "bool": {
            "must_not": {
                "bool": {
                    "should": [
                         {
                             "regexp":{
                                 "message": "путин.*"
                             }
                         },
                         {
                             "bool": {
                                 "must": [
                                     {
                                         "span_near": {...}
                                     },
                                     {
                                         "span_near": {...}
                                     }
                                 ]
                             }
                        }
                    ]
                }
            }
        }
    }
}

关于json - Elasticsearch “span and”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36908850/

相关文章:

javascript - 修改嵌套 JSON 对象

php - 使用 PHP 脚本编辑 JSON 数据

javascript - 如何按顺序获取嵌套数组的数组?

python - 我可以按混淆矩阵中的单元格来打开文件吗?

json - 类型错误 : Object is not JSON serializable

Elasticsearch 模糊查询 - max_expansions

elasticsearch - Elasticsearch多个搜索词

python - 如何查询Elasticsearch以按特定字段提升

elasticsearch - 在 Elasticsearch 中突出显示

elasticsearch - Elasticsearch 中的唯一记录