欢迎投稿

今日深度:

ElasticSearch 常用setting与mapping,

ElasticSearch 常用setting与mapping,


{
  "cust_2016090519205300000": {
    "settings": {
      "index": {
        "number_of_shards": "5",
        "provided_name": "cust_2016090519205300000",
        "max_result_window": "1000000000",
        "creation_date": "1519362414487",
        "analysis": {
          "analyzer": {
            "my_ngram_analyzer": {
              "tokenizer": "my_ngram_tokenizer"
            }
          },
          "tokenizer": {
            "my_ngram_tokenizer": {
              "token_chars": [
                "letter",
                "digit"
              ],
              "min_gram": "2",
              "type": "nGram",
              "max_gram": "3"
            }
          }
        },
        "number_of_replicas": "1",
        "uuid": "ERntEIMET8a0iwlT7paYjA",
        "version": {
          "created": "5060199"
        }
      }
    }
  }
}

analyzer用于设置自定义分词器;其中my_ngram_tokenizer 用于设置最小分词、最大分词  ,该分词器用于处理 无法精确查询中文字段;

{
  "cust_2016090519205300000": {
    "mappings": {
      "customer_type": {
        "properties": {
          "ClassID": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "_class": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "attr1517905675669": {
            "type": "long"
          },
          "birthday": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss"
          },
          "city": {
            "type": "text",
            "fields": {
              "id": {
                "type": "keyword",
                "index": false
              }
            },
            "analyzer": "ik_smart",
            "fielddata": true
          },
          "country": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            },
            "analyzer": "ik_max_word",
            "fielddata": true
          },
          "createTime": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss"
          },
          "custGrade": {
            "type": "long"
          },
          "custId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "custName": {
            "type": "text",
            "boost": 8,
            "store": true,
            "fields": {
              "keyword": {
                "type": "text"
              }
            },
            "analyzer": "my_ngram_analyzer",
            "include_in_all": true,
            "fielddata": true
          },
          "events": {
            "properties": {
              "recordCustId": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "recordEventTypeId": {
                "type": "float"
              },
              "recordFollowupState": {
                "type": "long"
              },
              "recordTime": {
                "type": "date",
                "format": "yyyy-MM-dd HH:mm:ss"
              }
            }
          },
          "followupState": {
            "type": "long"
          },
          "language": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "mobile": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            },
            "analyzer": "ik_max_word",
            "fielddata": true
          },
          "province": {
            "type": "text",
            "fields": {
              "id": {
                "type": "keyword",
                "index": false
              }
            },
            "analyzer": "ik_smart",
            "fielddata": true
          },
          "source": {
            "properties": {
              "type": {
                "type": "long"
              },
              "value": {
                "type": "long"
              }
            }
          },
          "tagCount": {
            "type": "nested",
            "properties": {
              "11": {
                "type": "long"
              },
              "12": {
                "type": "long"
              }
            }
          }
        }
      }
    }
  }
}

fields.keyword  是用于解决中文无法进行分词检索问题

date类型的字段增加format 用于 设置时间类型字段 取出来的时候 可以默认转换成特定的格式

"analyzer": "ik_smart"  ik_smart 是ES中自带的分词器,用于解决使用文本字段进行分组时候,出现的 自动分词问题,如 按照城市分组 “张家界”会变成 “张家”、“家界”这种

"analyzer": "my_ngram_analyzer" 自定义分词器,该分词器用于处理 中文字段无法精确匹配;

www.htsjk.Com true http://www.htsjk.com/Elasticsearch/36595.html NewsArticle ElasticSearch 常用setting与mapping, { "cust_2016090519205300000": { "settings": { "index": { "number_of_shards": "5", "provided_name": "cust_2016090519205300000", "max_result_window": "1000000000", "creation_date": "1519362414487", "an...
相关文章
    暂无相关文章
评论暂时关闭