美文网首页
ES 常用REST 语法

ES 常用REST 语法

作者: _孙行者_ | 来源:发表于2022-09-07 20:58 被阅读0次

创建Index

curl -X PUT http://xxx:9200/demo_index

写入数据

curl -X PUT http://xxx:9200/demo_index/demo_type/[id] -d '{jsondata}'

查看字段及结构 _mapping

curl -X GET http://xxx:9200/demo_index/_mapping
curl -X GET http://xxx:9200/demo_index/demo_type/_mapping

查询信息 _cat

curl -X GET http://xxx:9200/_cat/demo_index/
curl -X GET http://xxx:9200/_cat/demo_index/demo_type/

查总数 _count

curl -XGET 'localhost:9200/_count?pretty'

带不带value的查询的区别

term 查询

{
    "query": {
        "term": {
            "id": 123
        }
    }
}

terms 查询

{
    "query": {
        "terms": {
            "id": [
                7887813,
                6450174,
                17103990,
                28042521,
                5885609,
                28997931
            ]
        }
    }
}

查询有值

{
    "query": {
        "wildcard":{
            "name":"*"
        }
    }
}

查询无值(包括空字符串)

{
    "query": {
        "must_not" : {
             "name":{
                "wildcard":"*"
            }
        }
    }
}

且关系

{
    "must" : {
        "name" : {
            "term":"李"
        },
        "sex" : {
            "term":"男"
        }
    }
}

上面等同于: where name = ‘李’ and sex = ‘男’

{
    "must" : {
        "name" : {
            "term":"李"
        }
    },
    "must_not" : {
        "sex":{
            "term":"女"
        }
    }
}

上面等同于: where name = '李' and sex <> '女'

所以同级别的,是 and 关系。

或关系

{
    "shold": {
        "name": {
            "term": "李"
        },
        "sex": {
            "term": "男"
        }
    }
}

等同于 where name = ‘李’ or sex = '男'

且和或的关系

{
    "must" : {
        "name" : {
            "term":"李"
        }
    },
    "shold": {
        "age": {
            "term": "18"
        },
        "sex": {
            "term": "女"
        }
    }
}

等同于: where name = '李' and (age = 18 or sex = '女')

term 为什么用在keyword 上

match 和 wildcard

multimatch

相关文章

网友评论

      本文标题:ES 常用REST 语法

      本文链接:https://www.haomeiwen.com/subject/ytyluktx.html