elasticsearch基本操作

創(chuàng)建索引:

put http://192.168.102.100:9200/users?pretty
{
    "mappings":{
            "properties":{
                "userName":{
                    "type":"keyword"
                },
                "sex":{
                    "type":"keyword"
                },
                "age":{
                    "type":"integer"
                },
                "birthday":{
                    "type":"keyword"
                },
                "height":{
                    "type":"integer"
                }
        }
    }
    
}

查詢索引基本信息:

get http://192.168.102.100:9200/users/_settings
{
    "users": {
        "settings": {
            "index": {
                "routing": {
                    "allocation": {
                        "include": {
                            "_tier_preference": "data_content"
                        }
                    }
                },
                "number_of_shards": "1",
                "provided_name": "users",
                "creation_date": "1646192811120",
                "number_of_replicas": "1",
                "uuid": "Lx8ZeIYBQribMGVkz91C7Q",
                "version": {
                    "created": "8000199"
                }
            }
        }
    }
}

查詢索引mapping信息:

get http://192.168.102.100:9200/users/_mappings
{
    "users": {
        "mappings": {
            "properties": {
                "age": {
                    "type": "integer"
                },
                "birthday": {
                    "type": "keyword"
                },
                "height": {
                    "type": "integer"
                },
                "sex": {
                    "type": "keyword"
                },
                "userName": {
                    "type": "keyword"
                }
            }
        }
    }
}

插入數(shù)據(jù)

put http://192.168.102.100:9200/users/_doc/1
{
    "userName":"張三",
    "sex":"男",
    "age":25,
    "birthday":"1995-04-12",
    "height":175,
}

按ID查詢數(shù)據(jù):

get http://192.168.102.100:9200/users/_doc/1
{
    "_index": "users",
    "_id": "1",
    "_version": 1,
    "_seq_no": 0,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "userName": "張三",
        "sex": "男",
        "age": 25,
        "birthday": "1995-04-12",
        "height": 175
    }
}

查詢?nèi)繑?shù)據(jù):

post http://192.168.102.100:9200/users/_search
{
    "query":{
        "match_all":{}
    },
    "from":0,
    "size":100
}
Response:
{
    "took": 4,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 1,
        "hits": [
            {
                "_index": "users",
                "_id": "1",
                "_score": 1,
                "_source": {
                    "userName": "張三",
                    "sex": "男",
                    "age": 25,
                    "birthday": "1995-04-12",
                    "height": 175
                }
            }
        ]
    }
}

按條件查詢數(shù)據(jù):

post http://192.168.102.100:9200/users/_search
{
    "query":{
        "match":{
            "userName":"張三"
        }
    },
    "from":0,
    "size":100
}
response:
{
    "took": 5,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.2876821,
        "hits": [
            {
                "_index": "users",
                "_id": "1",
                "_score": 0.2876821,
                "_source": {
                    "userName": "張三",
                    "sex": "男",
                    "age": 25,
                    "birthday": "1995-04-12",
                    "height": 175
                }
            }
        ]
    }
}

`

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容