elasticsearch maping 示例

//mapping示例

curl -XPOST http://127.0.0.1:9200/blog/topics/_mapping -d'
{
	"topics": {
		"properties": {
			"status": {
				"type": "integer"
			},
			"name": {
				"type": "string",
				"store": "yes",
				"index": "analyzed",
				"indexAnalyzer": "ik",
				"searchAnalyzer": "ik"
			},
			"desc": {
				"type": "string",
				"store": "yes",
				"index": "analyzed",
				"indexAnalyzer": "ik",
				"searchAnalyzer": "ik"
			}
		}
	}
}'

//settings示例

curl -XPUT http://127.0.0.1:9200/blog/_settings -d'
{
        "index" : {
                "analysis" : {
                        "analyzer" : {
                                "pinyin_analyzer" : {
                                                "tokenizer" : "my_pinyin",
                                                "filter" : ["standard"]
                                }
                        },
                        "tokenizer" : {
                                "my_pinyin" : {
                                        "type" : "pinyin",
                                        "first_letter" : "append",
                                        "padding_char" : " "
                                }
                        }
                }
        }
}'

//示例

PUT http://127.0.0.1:9200/index1
{
  "settings": {
     "refresh_interval": "5s",
     "number_of_shards" :   1, // 一个主节点
     "number_of_replicas" : 0 // 0个副本,后面可以加
  },
  "mappings": {
    "_default_":{
      "_all": { "enabled":  false } // 关闭_all字段,因为我们只搜索title字段
    },
    "resource": { 
      "dynamic": false, // 关闭“动态修改索引”
      "properties": {
        "title": {
          "type": "string",
          "index": "analyzed",
          "fields": {
            "cn": {
              "type": "string",
              "analyzer": "ik"
            },
            "en": {
              "type": "string",
              "analyzer": "english"
            }
          }
        }
      }
    }
  }
}