Elasticsearch REST API使用

语法 含义
http://127.0.0.1:9200/_search 查询所有索引
http://127.0.0.1:9200/index1/_search 查询index1索引上数据
http://127.0.0.1:9200/index1,index2/_search 查询index1和index2索引上数据
http://127.0.0.1:9200/index*/_search 查询index开头索引上数据
http://127.0.0.1:9200/*index/_search 查询index结尾索引上数据
http://127.0.0.1:9200/*index*/_search 查询包含index索引上数据

get 嵌套查询

在一些复杂的查询中,比如我们要查询name为tom的,样例如下

 get请求
http://127.0.0.1:9200/index1/_search

{
    "query":{
        "match": {
            "name": "tom"
        }
    }
}

结果如下

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.2876821,
        "hits": [
            {
                "_index": "index1",
                "_type": "_doc",
                "_id": "aaaabbbb",
                "_score": 0.2876821,
                "_source": {
                    "@version": "1",                 
                    "name": "tom",
                    "info": {
                        "like": "swim"
                    }
                }
            }
        ]
    }
}

如果我们要查询info下面like为swim的 那么查询条件如下

 get请求
http://127.0.0.1:9200/index1/_search

{
    "query":{
        "match": {
            "info.like": "swim"
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容