MST
星途 面试题库

面试题:ElasticSearch基础查询语法应用

假设有一个ElasticSearch索引存储了图书信息,包括书名(title)、作者(author)、出版年份(publication_year)等字段。请写出查询语句,检索出2020年之后出版,且作者为'张三'的所有图书,按书名升序排列。
41.5万 热度难度
数据库ElasticSearch

知识考点

AI 面试

面试题答案

一键面试
{
    "query": {
        "bool": {
            "must": [
                {
                    "range": {
                        "publication_year": {
                            "gt": 2020
                        }
                    }
                },
                {
                    "match": {
                        "author": "张三"
                    }
                }
            ]
        }
    },
    "sort": [
        {
            "title": {
                "order": "asc"
            }
        }
    ]
}