Skip to content

Instantly share code, notes, and snippets.

@KunihikoKido
KunihikoKido / gist:0a3df0038f7e736c1812
Last active August 29, 2015 14:04
Medium Hello Elasticsearch import data
curl -XPUT 'localhost:9200/medium/blog/1' -d '{
"title": "Elasticsearch 特徴まとめ",
"description": "Elasticsearch Features — 主にシステムを中心とした特徴まとめ",
"creator": "Kunihiko Kido",
"link": "https://medium.com/hello-elasticsearch/elasticsearch-500996e47c70",
"tags": ["Elasticsearch"],
"pubDate": "2014-03-12T11:09"
}'
curl -XPUT 'localhost:9200/medium/blog/2' -d '{

##alt text GistList: TODO for coders alt text

# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
import json
import boto3
import logging
from elasticsearch import Elasticsearch
from elasticsearch import helpers
from elasticsearch.exceptions import ElasticsearchException
{
"category": "サッカー",
"query": {
"bool": {
"should": [{
"simple_query_string": {
"fields": ["text"],
"default_operator": "or",
"query": "\"サッカー\" "
}
{
"took": 8883,
"timed_out": false,
"_shards": {
"total": 90,
"successful": 90,
"failed": 0
},
"hits": {
"total": 2811,
{
"query": {
"bool": {
"must": [{
"simple_query_string": {
"query": "\"サッカー\"", // 1) 人が与える任意の分類・キーワード
"fields": ["text"] // 2) 検索対象フィールド
}
}],
"filter": [{
{
"doc": {
"text": "スターウォーズのスター・デストロイヤー型ドローン動画が話題に"
},
"aggs": {
"categories": {
"terms": {
"field": "category"
}
}
{
"took": 10,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"total": 1,
"matches": [],
"aggregations": {
@KunihikoKido
KunihikoKido / admin.py
Created August 1, 2013 06:34
Django Admin 画面でオブジェクト作成者毎のアクセス制限を実現するためのコード。 実際に使用する時には、それぞれのClassを継承して、Model、ModelAdmin を実装する。
# -*- coding: utf-8 -*-
from django.contrib import admin
from django.http import HttpResponse
class OwnerPermissionAdmin(admin.ModelAdmin):
def queryset(self, request):
qs = super(OwnerPermissionAdmin, self).queryset(request)
if request.user.is_superuser:
return qs
@KunihikoKido
KunihikoKido / sitecustomize.py
Created August 1, 2013 07:52
site-package/sitecustomize.py に配置
import sys
sys.setdefaultencoding('utf-8')