国产精品白浆熟女,国产偷亚洲偷欧美偷精品,,新免费无码国产在线看,国产激情久久久久影院老熟女

Elasticsearch教程(五) elasticsearch Mapping的創(chuàng)建

JSON 2016-08-22 18:49:20 150986

Elasticsearch  目錄

一、Mapping介紹

Elasticsearch  中, Mapping  是什么?

mapping  Elasticsearch  中的作用就是約束。

1.數(shù)據(jù)類型聲明

它類似于靜態(tài)語(yǔ)言中的數(shù)據(jù)類型聲明,比如聲明一個(gè)字段為String, 以后這個(gè)變量都只能存儲(chǔ)String類型的數(shù)據(jù)。同樣的, 一個(gè)number類型的 mapping  字段只能存儲(chǔ)number類型的數(shù)據(jù)。

2.Mapping它定義了 Type 的屬性。

"_ttl": {"enabled": false}

表示 ttl關(guān)閉,其實(shí)ttl默認(rèn)就是關(guān)閉。

3.指定分詞器。

"id": {
    "index": "not_analyzed",
    "type": "string"
}

指定字段 id不分詞,并且類型為 string

4.…………

二、創(chuàng)建Mapping


1.下面介紹一下HTTP的創(chuàng)建方式。我一般用Java 創(chuàng)建方式。

PUT http://123.123.123.123:9200/index/type/
{
  "settings": {
     //設(shè)置10個(gè)分片,理解為類似數(shù)據(jù)庫(kù)中的表分區(qū)中一個(gè)個(gè)分區(qū)的概念,不知道是否妥當(dāng)
     "number_of_shards": 10
  }, 
  "mappings": {
    "trades": {
      "_id": {
        "path": "id"
      },
      "properties": {
        "id": {
         "type": "integer",
        //id:自增數(shù)字
        //要求:查詢
         "store" : true
        },
        "name": { //名稱
         "type": "string"
        },
        "brand": { //品牌: PG,P&G,寶潔集團(tuán),寶潔股份,聯(lián)想集團(tuán),聯(lián)想電腦等 
          "type": "string"
        },
        "orderNo": { //訂單號(hào) :如ATTS000928732
          "type": "string",
          "index":  "not_analyzed"
        },
        "description": {
              //描述: 2015款玫瑰香型強(qiáng)生嬰兒沐浴露,550ml,包郵
              "type": "string",      
               "sort": true
		},
        "date": {
          "type": "date"
        },
        "city": {
          "type": "string"
        },
        "qty": {// index分詞無(wú)效
            "type": "float"
        },
        "price": {
              //價(jià)格: float index無(wú)效
             "type": "float"
        }
      }
    }
  }
}

上面是從其他地方抄過(guò)來(lái)的。因?yàn)槲也挥眠@種方式。

2.Java方式創(chuàng)建。

構(gòu)建 Mapping 

package com.sojson.core.elasticsearch.mapping;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import java.io.IOException;

import org.elasticsearch.common.xcontent.XContentBuilder;

public class ZhidaoMapping {

	public static XContentBuilder getMapping(){
		XContentBuilder mapping = null;
		try {
			mapping = jsonBuilder()
			.startObject()
			//開(kāi)啟倒計(jì)時(shí)功能
			.startObject("_ttl")
				.field("enabled",false)
				.endObject()
					.startObject("properties")
					.startObject("title")
						.field("type","string")
					.endObject()
					.startObject("question")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("answer")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("category")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("author")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("date")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("answer_author")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("answer_date")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("description")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("keywords")
						.field("type","string")
						.field("index","not_analyzed")
					.endObject()
					.startObject("read_count")
						.field("type","integer")
						.field("index","not_analyzed")
					.endObject()
					//關(guān)聯(lián)數(shù)據(jù)
					.startObject("list").field("type","object").endObject()
				.endObject()
			.endObject();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return mapping;
	}
}

創(chuàng)建 Mapping 

public static void createBangMapping(){
    PutMappingRequest mapping = Requests.putMappingRequest(INDEX).type(TYPE).source(ZhidaoMapping.getMapping());
    ESTools.client.admin().indices().putMapping(mapping).actionGet();
    
}

創(chuàng)建的時(shí)候,需要 index已經(jīng)創(chuàng)建才行,要不然會(huì)報(bào)錯(cuò)。

//構(gòu)建一個(gè)Index(索引)
CreateIndexRequest request = new CreateIndexRequest(INDEX); ESTools.client.admin().indices().create(request);

創(chuàng)建完畢在 Head  插件里查看或者Get請(qǐng)求。

http://123.123.123.123:9200/index/type/_mapping

得到的結(jié)果:

{
    "zhidao_index": {
        "mappings": {
            "zhidao_type": {
                "_ttl": {
                    "enabled": false
                },
                "properties": {
                    "answer": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "answerAuthor": {
                        "type": "string"
                    },
                    "answerDate": {
                        "type": "date",
                        "format": "strict_date_optional_time||epoch_millis"//這里出現(xiàn)了復(fù)合類型
                    },
                    "answer_author": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "answer_date": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "author": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "category": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "date": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "description": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "id": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "keywords": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "list": {
                        "type": "object"
                    },
                    "question": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "readCount": {
                        "type": "long"
                    },
                    "read_count": {
                        "type": "integer"
                    },
                    "title": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

Head插件查看

其實(shí) Mapping  ,你接觸 Elasticsearch  久一點(diǎn)也就那么回事。我們雖然知道 Elasticsearch  有根據(jù)數(shù)據(jù)識(shí)別創(chuàng)建 Mapping  ,但是最好是創(chuàng)建,并且指定分詞與否。這樣高效一點(diǎn)。


版權(quán)所屬:SO JSON在線解析

原文地址:http://zijieyoumin.cn/blog/86.html

轉(zhuǎn)載時(shí)必須以鏈接形式注明原始出處及本聲明。


如果本文對(duì)你有幫助,那么請(qǐng)你贊助我,讓我更有激情的寫下去,幫助更多的人。

關(guān)于作者
一個(gè)低調(diào)而悶騷的男人。
相關(guān)文章
Elasticsearch教程,Elasticsearch Java API創(chuàng)建Mapping,指定分詞器
Elasticsearch教程(六) elasticsearch Client創(chuàng)建
Elasticsearch教程 ,Elasticsearch count 查詢,Elasticsearch 查詢是否存在
Elasticsearch教程,Elasticsearch配置文件 — elasticsearch.yml
Elasticsearch 教程Elasticsearch部署阿里云集群,支持外網(wǎng)請(qǐng)求方式
Elasticsearch教程(八) elasticsearch delete 刪除數(shù)據(jù)(Java)
Elasticsearch教程(九) elasticsearch 查詢數(shù)據(jù) | 分頁(yè)查詢
Elasticsearch教程(四) elasticsearch head 插件安裝和使用
Elasticsearch 教程,Elasticsearch 日期查詢?cè)斀猓?em>Elasticsearch Date 查詢Java API
Elasticsearch教程,Elasticsearch安全篇,通過(guò)Nginx http basic 限制訪問(wèn)
最新文章
計(jì)算機(jī)網(wǎng)絡(luò)的相關(guān)內(nèi)容 239
SOJSON V6 JavaScript 解密技巧與分析 5802
微信客服人工電話95068:如何快速解封微信賬號(hào)(2025最新指南) 11575
Java Http請(qǐng)求,HttpURLConnection HTTP請(qǐng)求丟失頭信息,Head信息丟失解決方案 5036
實(shí)用API合集分享:教你輕松獲取IP地址的API合集 8803
Linux I/O重定向 6705
Ruby 循環(huán) - while、for、until、break、redo 和 retry 3990
Node.js:全局對(duì)象 3581
如何使用終端檢查L(zhǎng)inux上的內(nèi)存使用情況 3779
JavaScript對(duì)象詳細(xì)剖析 3252
最熱文章
免費(fèi)天氣API,天氣JSON API,不限次數(shù)獲取十五天的天氣預(yù)報(bào) 744432
最新MyEclipse8.5注冊(cè)碼,有效期到2020年 (已經(jīng)更新) 702904
蘋果電腦Mac怎么恢復(fù)出廠系統(tǒng)?蘋果系統(tǒng)怎么重裝系統(tǒng)? 678320
Jackson 時(shí)間格式化,時(shí)間注解 @JsonFormat 用法、時(shí)差問(wèn)題說(shuō)明 561904
我為什么要選擇RabbitMQ ,RabbitMQ簡(jiǎn)介,各種MQ選型對(duì)比 511792
Elasticsearch教程(四) elasticsearch head 插件安裝和使用 483712
Jackson 美化輸出JSON,優(yōu)雅的輸出JSON數(shù)據(jù),格式化輸出JSON數(shù)據(jù)... ... 299492
Java 信任所有SSL證書,HTTPS請(qǐng)求拋錯(cuò),忽略證書請(qǐng)求完美解決 246598
Elasticsearch教程(一),全程直播(小白級(jí)別) 232033
227509
支付掃碼

所有贊助/開(kāi)支都講公開(kāi)明細(xì),用于網(wǎng)站維護(hù):贊助名單查看

查看我的收藏

正在加載... ...