Han Yi
March 29, 2018
2.Data Model
2.1 Logical Model
2.2 Physical Model
1.Domain Model
PUT _cluster/settings
{
"persistent": {
"search": {
"remote": {
"cluster_one": {
"seeds": [
"127.0.0.1:9300"
]
},
"cluster_two": {
"seeds": [
"127.0.0.1:9301"
]
},
"cluster_three": {
"seeds": [
"127.0.0.1:9302"
]
}
}
}
}
}
GET /cluster_one:twitter,twitter/_search
{
"query": {
"match": {
"user": "kimchy"
}
}
}
{
"internet_products-2018-06-27-06-25-10": {
"mappings": {
"_doc": {
"properties": {
"alternateImageUrl": {
"type": "keyword"
},
"availableProductColors": {
"type": "nested",
"properties": {
"colorSwatchImageName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"colorSwatchName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"familyName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"productColorAlternateImageUrl": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"productColorImageUrl": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"averageRatingNumber": {
"type": "float"
},
"imageUrl": {
"type": "keyword"
},
"maxOriginalPrice": {
"type": "float"
},
"maxProductPrice": {
"type": "float"
},
"minOriginalPrice": {
"type": "float"
},
"minProductPrice": {
"type": "float"
},
"newProductEndDate": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"productBeginLiveDate": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"productNumber": {
"type": "keyword"
},
"productUrl": {
"type": "keyword"
},
"reviewQuantity": {
"type": "long"
},
"sku": {
"type": "nested",
"properties": {
"ageRangeList": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"alternativeImageUrl": {
"type": "keyword"
},
"categories": {
"type": "text",
"analyzer": "categoryFieldAnalyzer"
},
"categoryLevel": {
"properties": {
"lvl1": {
"type": "keyword"
},
"lvl2": {
"type": "keyword"
},
"lvl3": {
"type": "keyword"
},
"lvl4": {
"type": "keyword"
}
}
},
"colorFamilyName": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"colorName": {
"type": "text",
"analyzer": "colorFieldAnalyzer"
},
"combineColorList": {
"type": "text",
"analyzer": "commonFieldAnalyzer"
},
"combineSearchableList": {
"type": "text",
"analyzer": "commonFieldAnalyzer"
},
"currentPrice": {
"type": "float"
},
"imageUrl": {
"type": "keyword"
},
"productFeatureUrl": {
"type": "keyword"
},
"searchTermText": {
"type": "text",
"analyzer": "commonFieldAnalyzer"
},
"shoeWidthList": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"sizeDescription": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"sizeRangeList": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"styleName": {
"type": "text",
"analyzer": "commonFieldAnalyzer"
},
"styleNumber": {
"type": "keyword"
}
}
}
}
}
}
}
}
PUT logs
{
"mappings": {
"_doc": {
"_source": {
"includes": [
"*.count",
"meta.*"
],
"excludes": [
"meta.description",
"meta.other.*"
]
}
}
}
}
{
"mappings":{
"_doc":{
"dynamic_templates":[
{
"features":{
"match":"*_features",
"match_mapping_type":"string",
"mapping":{
"type":"string",
//should use synonym, stemming
"analyzer":"features_analyzer"
}
}
}
]
}
}
}
{
"internet_products-2018-06-27-06-25-10": {
"aliases": {
"internet_products": {}
},
"settings": {
"index": {
"number_of_shards": "1",
"provided_name": "internet_products-2018-06-27-06-25-10",
"creation_date": "1530080710871",
"analysis": {
"filter": {
"stemmer": {
"type": "snowball",
"language": "English"
},
"colorSynonym": {
"type": "synonym",
"synonyms": [
//...
]
},
"commonFieldSynonym": {
"type": "synonym",
"synonyms": [
//...
]
},
"categoryFieldSynonym": {
"type": "synonym",
"synonyms": [
//...
]
}
},
"analyzer": {
"commonFieldAnalyzer": {
"filter": [
"standard",
"lowercase",
"stemmer",
"commonFieldSynonym"
],
"tokenizer": "standard"
},
"colorFieldAnalyzer": {
"filter": [
"standard",
"lowercase",
"stemmer",
"colorSynonym"
],
"tokenizer": "standard"
},
"categoryFieldAnalyzer": {
"filter": [
"standard",
"lowercase",
"stemmer",
"categoryFieldSynonym"
],
"tokenizer": "standard"
}
}
},
"number_of_replicas": "0",
"uuid": "Cl9s4MqKRhWgqEICR97iKw",
"version": {
"created": "6020299"
}
}
},
"mappings": {
"_doc": {
"properties": {
"alternateImageUrl": {
"type": "keyword"
},
"availableProductColors": {
"type": "nested",
"properties": {
"colorSwatchImageName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"colorSwatchName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"familyName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"productColorAlternateImageUrl": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"productColorImageUrl": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"averageRatingNumber": {
"type": "float"
},
"imageUrl": {
"type": "keyword"
},
"maxOriginalPrice": {
"type": "float"
},
"maxProductPrice": {
"type": "float"
},
"minOriginalPrice": {
"type": "float"
},
"minProductPrice": {
"type": "float"
},
"newProductEndDate": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"productBeginLiveDate": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"productNumber": {
"type": "keyword"
},
"productUrl": {
"type": "keyword"
},
"reviewQuantity": {
"type": "long"
},
"sku": {
"type": "nested",
"properties": {
"ageRangeList": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"alternativeImageUrl": {
"type": "keyword"
},
"categories": {
"type": "text",
"analyzer": "categoryFieldAnalyzer"
},
"categoryLevel": {
"properties": {
"lvl1": {
"type": "keyword"
},
"lvl2": {
"type": "keyword"
},
"lvl3": {
"type": "keyword"
},
"lvl4": {
"type": "keyword"
}
}
},
"colorFamilyName": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"colorName": {
"type": "text",
"analyzer": "colorFieldAnalyzer"
},
"combineColorList": {
"type": "text",
"analyzer": "commonFieldAnalyzer"
},
"combineSearchableList": {
"type": "text",
"analyzer": "commonFieldAnalyzer"
},
"currentPrice": {
"type": "float"
},
"imageUrl": {
"type": "keyword"
},
"productFeatureUrl": {
"type": "keyword"
},
"searchTermText": {
"type": "text",
"analyzer": "commonFieldAnalyzer"
},
"shoeWidthList": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"sizeDescription": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"sizeRangeList": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
},
"styleName": {
"type": "text",
"analyzer": "commonFieldAnalyzer"
},
"styleNumber": {
"type": "keyword"
}
}
}
}
}
}
}
}
POST _analyze
{
"tokenizer": "keyword",
"char_filter": [ "html_strip" ],
"text": "<p>I'm so <b>happy</b>!</p>"
}
[ \nI'm so happy!\n ]
//default standard analyzer will give
[ I'm, so, happy ]
PUT my_index
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"char_filter": [
"my_char_filter"
]
}
},
"char_filter": {
"my_char_filter": {
"type": "mapping",
"mappings": [
":) => _happy_",
":( => _sad_"
]
}
}
}
}
}
POST my_index/_analyze
{
"analyzer": "my_analyzer",
"text": "I'm delighted about it :("
}
[ I'm, delighted, about, it, _sad_ ]
PUT my_index
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"char_filter": [
"my_char_filter"
]
}
},
"char_filter": {
"my_char_filter": {
"type": "pattern_replace",
"pattern": "(\\d+)-(?=\\d)",
"replacement": "$1_"
}
}
}
}
}
POST my_index/_analyze
{
"analyzer": "my_analyzer",
"text": "My credit card is 123-456-789"
}
[ My, credit, card, is 123_456_789 ]
POST _analyze
{
"tokenizer": "standard",
"text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
}
[ The, 2, QUICK, Brown, Foxes, jumped, over, the, lazy, dog's, bone ]
{
"internet_products-2018-06-27-06-25-10": {
"aliases": {
"internet_products": {}
},
"settings": {
"index": {
"number_of_shards": "1",
"provided_name": "internet_products-2018-06-27-06-25-10",
"creation_date": "1530080710871",
"analysis": {
"filter": {
"stemmer": {
"type": "snowball",
"language": "English"
},
"commonFieldSynonym": {
"type": "synonym",
"synonyms": [
//...
]
}
},
"analyzer": {
"commonFieldAnalyzer": {
"filter": [
"standard",
"lowercase",
"stemmer",
"commonFieldSynonym"
],
"tokenizer": "standard"
}
}
},
"number_of_replicas": "0",
"uuid": "Cl9s4MqKRhWgqEICR97iKw",
"version": {
"created": "6020299"
}
}
},
"mappings": {
"_doc": {
"properties": {
"sku": {
"type": "nested",
"properties": {
"ageRangeList": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "commonFieldAnalyzer"
}
}
}
}
}
}
}
}
GET _analyze
{
"analyzer": "smartcn",
"text":"战车翻了!德国0-2爆冷出局 中超外援进首球"
}
{
"tokens": [
{
"token": "战车",
"start_offset": 0,
"end_offset": 2,
"type": "word",
"position": 0
},
{
"token": "翻",
"start_offset": 2,
"end_offset": 3,
"type": "word",
"position": 1
},
{
"token": "了",
"start_offset": 3,
"end_offset": 4,
"type": "word",
"position": 2
},
{
"token": "德国",
"start_offset": 5,
"end_offset": 7,
"type": "word",
"position": 4
},
{
"token": "0",
"start_offset": 7,
"end_offset": 8,
"type": "word",
"position": 5
},
{
"token": "2",
"start_offset": 9,
"end_offset": 10,
"type": "word",
"position": 7
},
{
"token": "爆冷",
"start_offset": 10,
"end_offset": 12,
"type": "word",
"position": 8
},
{
"token": "出局",
"start_offset": 12,
"end_offset": 14,
"type": "word",
"position": 9
},
{
"token": "中",
"start_offset": 15,
"end_offset": 16,
"type": "word",
"position": 10
},
{
"token": "超",
"start_offset": 16,
"end_offset": 17,
"type": "word",
"position": 11
},
{
"token": "外援",
"start_offset": 17,
"end_offset": 19,
"type": "word",
"position": 12
},
{
"token": "进",
"start_offset": 19,
"end_offset": 20,
"type": "word",
"position": 13
},
{
"token": "首",
"start_offset": 20,
"end_offset": 21,
"type": "word",
"position": 14
},
{
"token": "球",
"start_offset": 21,
"end_offset": 22,
"type": "word",
"position": 15
}
]
}
//Array of Object
PUT my_index/_doc/1
{
"group" : "fans",
"user" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
}
//Array of object
{
"group" : "fans",
"user.first" : [ "alice", "john" ],
"user.last" : [ "smith", "white" ]
}
//Query
GET my_index/_search
{
"query": {
"bool": {
"must": [
{ "match": { "user.first": "Alice" }},
{ "match": { "user.last": "Smith" }}
]
}
}
}
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"my_join_field": {
"type": "join",
"relations": {
"question": "answer"
}
}
}
}
}
}
PUT my_index/_doc/1?refresh
{
"text": "This is a question",
"my_join_field": {
"name": "question"
}
}
PUT my_index/_doc/3?routing=1&refresh
{
"text": "This is an answer",
"my_join_field": {
"name": "answer",
"parent": "1"
}
}
GET /_search
{
"query": {
"has_child": {
"type": "answer",
"query": {
"term": {
"text": "answer"
}
}
}
}
}
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"user": {
"type": "nested"
}
}
}
}
}
PUT my_index/_doc/1
{
"group" : "fans",
"user" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
}
GET my_index/_search
{
"query": {
"nested": {
"path": "user",
"query": {
"bool": {
"must": [
{ "match": { "user.first": "Alice" }},
{ "match": { "user.last": "Smith" }}
]
}
}
}
}
}
{
"properties":{
"DIM_PATH_INDX":{
"type":"text",
"analyzer":"dimension_path_analyzer",
"fields":{
"reverse":{
"type":"text",
"analyzer":"reverse_dimension_path_analyzer"
}
}
},
"INET_PRDT_NUM":{
"type":"keyword"
}
}
}