Last active
April 25, 2018 09:20
-
-
Save readytopark/eef68890a20af6f168fe8118d3a8cd3b to your computer and use it in GitHub Desktop.
elasticsearch for counting the most popular tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
elasticsearch for counting the most popular tags | |
# Index Settings | |
- mapping: Make sure 'tag' field is "eact value" string type | |
curl -XPUT 'http://localhost:9200/mediaclip/' -d '{ | |
"settings": { | |
"index": { | |
"number_of_shards": 5, | |
"number_of_replicas": 1 | |
} | |
}, | |
"mappings": { | |
"tag": { | |
"properties": { | |
"tag": { | |
"type": "string", | |
"index": "not_analyzed" | |
} | |
} | |
} | |
} | |
} | |
' | |
# Bulk indexing | |
curl -XPOST "http://localhost:9200/_bulk" -d' | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "방탄소년단" } | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "엑소" } | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "엑소" } | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "엑소" } | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "방탄소년단" } | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "엑소" } | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "걸스데이" } | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "엑소" } | |
{ "index": { "_index": "mediaclip", "_type": "tag" }} | |
{ "tag": "엑소" } | |
' | |
curl -s -XPOST localhost:9200/_bulk --data-binary "@filename" | |
# Search | |
curl -XPOST "http://localhost:9200/mediaclip/_search?pretty=true" | |
# Get current mapping status | |
curl -XGET localhost:9200/mediaclip/_mapping/tag | |
# Delete | |
curl -XDELETE "http://localhost:9200/mediaclip" -d '' | |
# Aggregation | |
curl -XGET "http://localhost:9200/mediaclip/tag/_search?pretty=true" -d ' | |
{ | |
"size": 0, | |
"aggs": { | |
"popular_tags": { | |
"terms": { | |
"field": "tag", | |
"size": 200 | |
} | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment