Elasticsearch 一些命令彙總 以及學習總結

Krisji發表於2019-04-30

es 一些記錄 以及學習總結

1 安裝IK 分詞
/usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip
注意:要指定對應的es版本的分詞外掛
2 建立索引 相當於建立資料庫
  curl -XPUT http://localhost:9200/products?pretty
3 建立索引文件 類似資料的欄位吧
  curl -H'Content-Type: application/json' -XPUT http://localhost:9200/products/_mapping/_doc?pretty -d'{
  "properties": {
    "type": { "type": "keyword" } ,
    "title": { "type": "text", "analyzer": "ik_smart" },
    "long_title": { "type": "text", "analyzer": "ik_smart" },
    "category_id": { "type": "integer" },
    "category": { "type": "keyword" },
    "category_path": { "type": "keyword" },
    "description": { "type": "text", "analyzer": "ik_smart" },
    "price": { "type": "scaled_float", "scaling_factor": 100 },
    "on_sale": { "type": "boolean" },
    "rating": { "type": "float" },
    "sold_count": { "type": "integer" },
    "review_count": { "type": "integer" },
    "skus": {
      "type": "nested",
      "properties": {
        "title": { "type": "text", "analyzer": "ik_smart", "copy_to": "skus_title" },
        "description": { "type": "text", "analyzer": "ik_smart", "copy_to": "skus_description" },
        "price": { "type": "scaled_float", "scaling_factor": 100 }
      }
    },
    "properties": {
      "type": "nested",
      "properties": {
        "name": { "type": "keyword" },
        "value": { "type": "keyword", "copy_to": "properties_value" },
        "search_value": { "type": "keyword" }
      }
    }
  }
}'
注意事項:
1 nested 代表建立複雜資料 
2 copy_to 主要做查詢的特定對映的資料
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章