Skip to content

Instantly share code, notes, and snippets.

@GarKoZ
Last active July 17, 2019 06:17
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 GarKoZ/f88a50a931adf7ee351f6cf001064fe2 to your computer and use it in GitHub Desktop.
Save GarKoZ/f88a50a931adf7ee351f6cf001064fe2 to your computer and use it in GitHub Desktop.
DELETE /thairath
PUT thairath
{
"settings": {
"analysis": {
"analyzer": {
"trigrams": {
"tokenizer": "trigram_tokenizer",
"filter": [
"lowercase"
]
},
"analyzer_shingle":{
"tokenizer":"icu_tokenizer",
"filter":[
"filter_shingle"
]
}
},
"tokenizer": {
"trigram_tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 3,
"token_chars": []
}
},
"filter":{
"filter_shingle":{
"type": "shingle",
"max_shingle_size":3,
"min_shingle_size":2,
"output_unigrams":"true"
}
}
}
},
"mappings": {
"news": {
"properties": {
"news_title": {
"type": "text",
"analyzer": "trigrams"
},
"news_content": {
"type": "text",
"analyzer": "analyzer_shingle"
},
"views" :{
"type": "integer"
},
"likes" :{
"type": "integer"
}
}
}
}
}
POST _bulk
{ "index": {"_index": "thairath", "_type": "news", "_id": "1"}}
{ "news_title": "รมว.ไอซีที ยินดี 'ไทยรัฐออนไลน์' คว้าอันดับ 9 เว็บยอดนิยม", "news_content": "น.อ.อนุดิษฐ์ นาครทรรพ รมว.ไอซีที แสดงความยินดี เว็บไซต์ไทยรัฐออนไลน์ หลังคว้าอันดับ 2 เว็บข่าว และอันดับ 9 เว็บยอดนิยม พร้อมชื่นชมเป็นเว็บไซต์ข่าวเร็ว เขียนข่าวภายใต้ข้อเท็จจริง...", "likes": 13, "publishDate" : "2019-02-01"}
{ "index": {"_index": "thairath", "_type": "news", "_id": "2"}}
{ "news_title": "เปิดกฎหมาย เลือกตั้ง62 ลักษณะต้องห้ามส.ส.ดับฝันลอตแรก 107 คน- 3 นายกฯ", "news_content":"ในที่สุดกกต.ประกาศออกมาแล้ว ว่าผู้สมัครเลือกตั้งส.ส.รวมกว่า 1 หมื่นคน ในส่วนส.ส.แบบบัญชีรายชื่อมี 107 คนขาดคุณสมบัติ ส่วนผู้ที่ถูกเสนอชื่อนายกรัฐมนตรี ไม่ผ่าน 3 คน ส่วนส.ส.เขตยังรอประกาศ", "likes": 3, "publishDate" : "2019-02-17"}
{ "index": {"_index": "thairath", "_type": "news", "_id": "3"}}
{ "news_title": "เลขที่รักจงมา พาสำรวจ 10 อันดับหวยขายดี คนดวงดีเหมายกแผงไปแล้ว","news_content":"ไทยรัฐออนไลน์ พาคนรักเลขสำรวจแผงลอตเตอรี่ ก่อนหวยออก 16 ก.พ.62 พบเลขยอดนิยมวันวาเลนไทน์ 14, 28, 29 ถูกจับจองเกือบเกลี้ยงแผง... ", "likes": 7, "publishDate" : "2019-02-10"}
{ "index": {"_index": "thairath", "_type": "news", "_id": "4"}}
{ "news_title": "'เจ๊บ้าบิ่น' ฟ้องกลับ ทนายตั้ม–หมวดจรูญ ข้อหาแจ้งความเท็จ คดีหวย30ล้าน", "news_content":"พยานหวย 30 ล้าน ฟ้องกลับ 'ทนายตั้ม–หมวดจรูญ' ข้อหาแจ้งความเท็จ หลังอัยการกาญจน์ สั่งไม่ฟ้องคดีขายหวยเกินราคา", "likes": 0, "publishDate" : "2019-03-01"}
{ "index": {"_index": "thairath", "_type": "news", "_id": "5"}}
{ "news_title":"'เดินหลงทางในวัด' ฝันสยอง มองเห็นเลขเด็ดโผล่ต้นตะเคียนวัดดังศรีสะเกษ","news_content":"ยังมีชาวบ้านพากันไปกราบไหว้หลวงปู่สรวงอย่างต่อเนื่อง ภายหลังนักเลงหวยได้เลขเด็ด เสี่ยงโชคถูกหลายงวดติดต่อกัน กระทั่งเมื่อวันที่ 14 ก.พ. ที่ผ่านมา ชาวอำเภอเมืองศรีสะเกษ กลับจากทำบุญที่วัดไพรพัฒนา ตำบลไพรพัฒนา อำเภอภูสิงห์ จังหวัดศรีสะเกษ เมื่อถึงบ้านตกกลางคืนหลับฝัน เดินหลงทางเป็นเขาวงกตอยู่ในวัด กระทั่งเจอต้นตะเคียนบอกใบ้หวย ได้ฝันเห็นเลขเด็ด", "likes": 5, "publishDate" : "2019-02-28"}
{ "index": {"_index": "thairath", "_type": "news", "_id": "6"}}
{ "news_title": "ดาววิศวะ ม.ดัง รมควันตายวันวาเลนไทน์ ทิ้งข้อความนำร่างออกก่อนตี 3","news_content":"นักศึกษาสาว คณะวิศวกรรมศาสตร์ มหาวิทยาลัยเอกชนชื่อดังในกรุงเทพฯ จุดเตาไฟฟ้ารมควันฆ่าตัวตายในห้องพัก โดยเหตุสลดนี้เปิดเผยโดย พ.ต.ต.รักเกียรติ์ ปทุมวัลย์ สว.(สอบสวน) สน.ทุ่งสองห้อง หลังจากทราบเรื่องได้เข้าตรวจสอบที่เกิดเหตุพบภายในห้องพัก ยังมีกลิ่นของควันอบอวลทั่วห้อง ภายในห้องพบร่างผู้หญิงยังอยู่ในชุดนักศึกษานอนเสียชีวิต สภาพศพนอนกอดตุ๊กตาหมี ทราบชื่อน.ส.วิชิตา คงทอง อายุ 25 ปี และพบหลักฐานสำคัญคือกระทะไฟฟ้าที่มีถ่านเผาไหม้ ", "likes": 11, "publishDate" : "2019-02-05"}
{ "index": {"_index": "thairath", "_type": "news", "_id": "7"}}
{ "news_title": "16 แน่นอนกว่า 14 พาไปดูสถิติหวยออกวันที่ 16 ก.พ. เลขเด็ด ดัง เด่น มาเต็มๆ","news_content":"14 กุมภาฯ วันวาเลนไทน์ ของขวัญจากใจ ฉันมอบแด่เธอ พาไปดูสถิติ 'หวย' ออกวันที่ 16 ก.พ. ย้อนหลัง 11 ปี เลขเด็ด เลขดัง เลขเด่น มาเต็มๆ", "likes": 4, "publishDate" : "2019-02-01"}
GET /thairath/news/_mapping
GET /thairath/news/_search
{
"query" : {
"function_score": {
"query" : {
"match": { "message": "elasticsearch" }
},
"script_score" : {
"script" : {
"source" : "doc['likes'].value / 10 "
}
}
}
}
}
POST /thairath/news/_search
{
"query": {
"function_score": {
"query": {
"multi_match" : {
"query": "เลขเด็ด",
"fields": [ "news_title", "news_content"],
"type": "most_fields"
}
},
"script_score": {
"script": {
"params": {
"a" : 2
},
"source": "Math.log(params.a + doc['likes'].value)"
}
}
}
}
}
POST /thairath/news/_search
{
"query": {
"function_score": {
"gauss": {
"publishDate": {
"origin": "2019-02-28",
"scale": "20d",
"offset": "2d",
"decay" : 0.5
}
}
}
}
}
POST /thairath/news/_search
{
"query": {
"function_score": {
"query": {
"multi_match" : {
"query": "เลขเด็ด",
"fields": [ "news_title", "news_content"],
"type": "most_fields"
}
},
"functions": [
{
"gauss": {
"publishDate": {
"origin": "2019-02-28",
"scale": "20d",
"offset": "2d",
"decay" : 0.5
}
}
},
{
"field_value_factor": {
"field": "likes",
"factor": 0.05,
"modifier": "ln2p",
"missing": 1
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment