索引使用

索引创建

创建示例 

使用 copyTO

优点:

缺点:

2. 不使用 copy_to 的方式(多字段搜索)

优点:

缺点:

PUT /document_index
{
  "settings": { // 分词配置
    "analysis": {
      "analyzer": {
        "ik_smart_analyzer": {
          "type": "custom",
          "tokenizer": "ik_smart"
        },
        "ik_max_analyzer": {
          "type": "custom", 
          "tokenizer": "ik_max_word"
        }
      }
    },
    "index": { // 分片配置
      "number_of_shards": 1,
      "number_of_replicas": 1
    }
  },
  "mappings": { // 具体的字段配置
    "properties": {
      "id": {
        "type": "long",
        "copy_to": "all_fields"  // 复制到全字段
      },
      "page": {
        "type": "integer",
        "copy_to": "all_fields"  // 复制到全字段
      },
      "text": {
        "type": "text",
        "analyzer": "ik_max_analyzer",
        "search_analyzer": "ik_smart_analyzer",
        "copy_to": "all_fields"  // 复制到全字段
      },
      "all_fields": {
        "type": "text",
        "analyzer": "ik_max_analyzer",
        "search_analyzer": "ik_smart_analyzer"
      }
    }
  }
}