ElasticSearch mapping(索引的數據結構,類似於數據庫表中的各個字段定義)


1、創建索引,定義mappings屬性。

類型為keyword是不會被分詞的。

index: 默認為true,設置為false,那么這個字段就不會被索引,不會被查詢到。

 

 創建好后,在http://localhost:9100/  中查看索引的信息

類型為keyword,就不會被分詞,如手機號,QQ號。 

 

2、查看分詞效果

 

 返回如下:

{
    "tokens": [
        {
            "token": "nick",
            "start_offset": 0,
            "end_offset": 4,
            "type": "<ALPHANUM>",
            "position": 0
        },
        {
            "token": "is",
            "start_offset": 5,
            "end_offset": 7,
            "type": "<ALPHANUM>",
            "position": 1
        },
        {
            "token": "a",
            "start_offset": 8,
            "end_offset": 9,
            "type": "<ALPHANUM>",
            "position": 2
        },
        {
            "token": "good",
            "start_offset": 10,
            "end_offset": 14,
            "type": "<ALPHANUM>",
            "position": 3
        },
        {
            "token": "man",
            "start_offset": 15,
            "end_offset": 18,
            "type": "<ALPHANUM>",
            "position": 4
        }
    ]
}

  

3、增加索引的屬性

增加id和age屬性。默認是不能修改屬性的,要先刪除,在增加。

 

 屬性類型可以為以下幾種

"properties": {
"birthday": {
"type": "date"
},
"score": {
"type": "float"
},
"sex": {
"type": "byte"
},
"is_teenger": {
"type": "boolean"
},
"id": {
"type": "long"
},
"relationship": {
"type": "object"
},
"money2": {
"type": "float"
},
"age": {
"type": "integer"
},
"money1": {
"type": "double"
},
"realname": {
"type": "text"
},
"username": {
"index": false,
"type": "keyword"
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM