Tuesday, August 13, 2019

ตัวอย่างการทำ index โดยใข้ ngram ใน elasticsearch

PUT event_checkpoint
{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "properties": {
      "event_id": {
        "type": "text"
      },
      "event_name": {
        "type": "text"
      },
      "event_startdate": {
        "type" : "date",
        "format" : "yyyy-MM-dd"
      },
      "event_enddate": {
        "type" : "date",
        "format" : "yyyy-MM-dd"
      },
      "checkpoint_id": {
        "type": "text"
      },
      "checkpoint_name": {
        "type": "text"
      },
      "checkin_date": {
        "type" : "date",
        "format" : "yyyy-MM-dd"
      },
      "checkin_time": {
        "type" : "date",
        "format" : "HH:mm:ss"
      },
      "checkin_code": {
        "type": "text"
      },
      "checkin_point": {
        "type": "integer"
      },
      "checkin_accumulated_point": {
        "type": "integer"
      },
      "create_datetime": {
        "type" : "date",
        "format" : "yyyy-MM-dd HH:mm:ss"
      }
    }
  }
}

-----------------------------------------------------------

PUT event_checkpoint
{
  "settings": {
    "number_of_shards": 1,
    "analysis": {
      "tokenizer": {
        "ngram_tokenizer": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 4
        }
      },
      "analyzer": {
        "ngram_tokenizer_analyzer": {
          "type": "custom",
          "tokenizer": "ngram_tokenizer",
          "filter": "lowercase"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "record_id": {
        "analyzer": "ngram_tokenizer_analyzer",
        "type": "text"
      },
      "event_id": {
        "analyzer": "ngram_tokenizer_analyzer",
        "type": "text"
      },
      "event_name": {
        "analyzer": "ngram_tokenizer_analyzer",
        "type": "text"
      },
      "event_startdate": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "event_enddate": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "checkpoint_id": {
        "analyzer": "ngram_tokenizer_analyzer",
        "type": "text"
      },
      "checkpoint_name": {
        "analyzer": "ngram_tokenizer_analyzer",
        "type": "text"
      },
      "checkin_date": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "checkin_time": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "checkin_code": {
        "analyzer": "ngram_tokenizer_analyzer",
        "type": "text"
      },
      "checkin_point": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "checkin_accumulated_point": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "create_datetime": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

-----------------------------------------------------------

PUT tci
{
    "settings": {
      "number_of_shards": 1,
      "analysis": {
         "tokenizer": {
            "ngram_tokenizer": {
               "type": "nGram",
               "min_gram": 3,
               "max_gram": 4
            }
         },
         "analyzer": {
            "ngram_tokenizer_analyzer": {
               "type": "custom",
               "tokenizer": "ngram_tokenizer",
               "filter":"lowercase"
            }
         }
      }
   },
    "mappings": {
        "article": {
            "properties": {
              "article_abstract": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "affiliation": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "article_create_dtm": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "article_id": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "author": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "country": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "issue_num": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "journal_country_id": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "journal_country_name": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "journal_id": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "journal_title": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "keyword": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "pissn": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "publisher": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "reference": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "title": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "volume": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "year": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "eissn": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "area": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "doi": {
                "type": "text",
                "analyzer": "ngram_tokenizer_analyzer"
              },
              "is_tci_db": {
                "type": "text"
              },
              "is_aci_db": {
                "type": "text"
              }
            }
        }
    }
}

No comments:

Post a Comment