Skip to content

Instantly share code, notes, and snippets.

@cheehoo
Created April 30, 2014 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheehoo/b1b0e2d9e8dd4e05f59d to your computer and use it in GitHub Desktop.
Save cheehoo/b1b0e2d9e8dd4e05f59d to your computer and use it in GitHub Desktop.
#create index and update analyzer
curl -XPOST 'localhost:9200/test_dev'
curl -XPOST 'localhost:9200/test_dev/_close'
curl -XPUT 'localhost:9200/test_dev/_settings' -d '{
"analysis" : {
"analyzer":{
"standard":{
"type":"standard",
"stopwords":"_none_"
},
"string_lowercase" : {
"tokenizer" : "keyword",
"filter" : "lowercase"
}
}
}
}'
curl -XPOST 'localhost:9200/test_dev/_open'
#Create mapping
curl -XPOST 'localhost:9200/test_dev/media/_mapping' -d '{
"media": {
"properties": {
"AUDIO": {
"type": "string"
},
"BILLINGTYPE_ID": {
"type": "long"
},
"CATMEDIA_CDATE": {
"type": "date",
"format": "dateOptionalTime"
},
"CATMEDIA_NAME": {
"type": "string"
},
"CATMEDIA_RANK": {
"type": "long"
},
"CAT_ID": {
"type": "long"
},
"CAT_NAME": {
"type": "string",
"analyzer": "string_lowercase",
"include_in_all": true
},
"CAT_PARENT": {
"type": "long"
},
"CHANNEL_ID": {
"type": "long"
},
"CKEY": {
"type": "long"
},
"DISPLAY_NAME": {
"type": "string",
"analyzer": "string_lowercase",
"include_in_all": true
},
"FTID": {
"type": "string"
},
"GENRE": {
"type": "string"
},
"ITEMCODE": {
"type": "string"
},
"KEYWORDS": {
"type": "string"
},
"LANG_ID": {
"type": "long"
},
"LONG_DESCRIPTION": {
"type": "string"
},
"MAPPINGS": {
"type": "string",
"analyzer": "string_lowercase",
"include_in_all": true
},
"MEDIA_ID": {
"type": "long"
},
"MEDIA_PKEY": {
"type": "string"
},
"PERFORMER": {
"type": "string"
},
"PLAYER": {
"type": "string"
},
"POSITION": {
"type": "long"
},
"PRICE": {
"type": "double"
},
"PRIORITY": {
"type": "long"
},
"SHORTCODE": {
"type": "string"
},
"SHORT_DESCRIPTION": {
"type": "string"
},
"TYPE_ID": {
"type": "long"
},
"VIEW_ID": {
"type": "long"
}
}
}
}'
#create documents
curl -XPOST 'localhost:9200/test_dev/media' -d '{
"DISPLAY_NAME": "Happy People",
"PRICE": 1.5,
"AUDIO": "http://musicube.thecube.my/base/preview/053/533936/533936-MP3-CMT-P.mp3",
"CHANNEL_ID": 1,
"CAT_PARENT": 557,
"MEDIA_ID": 9556,
"GENRE": "Happy People",
"MEDIA_PKEY": "533936",
"COMPOSER": null,
"PLAYER": null,
"CATMEDIA_NAME": "Happy People",
"FTID": null,
"VIEW_ID": 241,
"POSITION": 128,
"ITEMCODE": "53952",
"CAT_ID": 561,
"PRIORITY": 100,
"CKEY": 527749,
"CATMEDIA_RANK": 3,
"BILLINGTYPE_ID": 1,
"CAT_NAME": "R&B/Soul",
"KEYWORDS": null,
"LONG_DESCRIPTION": null,
"SHORT_DESCRIPTION": null,
"TYPE_ID": 76,
"ARTIST_GENDER": null,
"PERFORMER": "The Temptations",
"MAPPINGS": "1_241_561_R&B/Soul_557_128_1.5",
"SHORTCODE": "0012139690",
"CATMEDIA_CDATE": "2012-10-16T03:32:31.000Z",
"LANG_ID": 1
}'
curl -XPOST 'localhost:9200/test_dev/media' -d '{
"DISPLAY_NAME": "Happy People",
"PRICE": 5,
"AUDIO": "http://musicube.thecube.my/base/preview/058/584092/584092-MP3-FTD-P.mp3",
"CHANNEL_ID": 1,
"CAT_PARENT": 981,
"MEDIA_ID": 76367,
"GENRE": "Happy People",
"MEDIA_PKEY": "584092",
"COMPOSER": null,
"PLAYER": null,
"CATMEDIA_NAME": "Happy People",
"FTID": null,
"VIEW_ID": 43,
"POSITION": 1439,
"ITEMCODE": null,
"CAT_ID": 983,
"PRIORITY": 80,
"CKEY": 527749,
"CATMEDIA_RANK": 3,
"BILLINGTYPE_ID": 1,
"CAT_NAME": "Rock & Indie",
"KEYWORDS": null,
"LONG_DESCRIPTION": null,
"SHORT_DESCRIPTION": null,
"TYPE_ID": 74,
"ARTIST_GENDER": null,
"PERFORMER": "The Temptations",
"MAPPINGS": "1_43_983_Rock & Indie_981_1439_5",
"SHORTCODE": null,
"CATMEDIA_CDATE": "2013-01-09T14:56:48.000Z",
"LANG_ID": 1
}'
#Query document with match
curl -XPOST 'localhost:9200/test_dev/media/_search?pretty=true' -d '{
"query" : { "match" : {"DISPLAY_NAME" : "Happy People"} }
}
#Query document with span_first/near/term
curl -XPOST 'localhost:9200/test_dev/media/_search?pretty=true' -d '{
"from" : 100,
"size" : 100,
"query" : {
"span_first" : {
"match" : {
"span_near" : {
"clauses" : [
{ "span_term" : { "DISPLAY_NAME" : "happy" } },
{ "span_term" : { "DISPLAY_NAME" : "people" } }
],
"slop" : 1,
"in_order" : true
}
},
"end" : 2
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment