Skip to content

Instantly share code, notes, and snippets.

@takaheraw
Last active January 17, 2016 08:44
Show Gist options
  • Save takaheraw/146d70f479d492a7d268 to your computer and use it in GitHub Desktop.
Save takaheraw/146d70f479d492a7d268 to your computer and use it in GitHub Desktop.
$ curl -XPOST 'http://localhost:9200/twitter' -d '
{
  "settings": {
    "analysis": {
      "analyzer": {
        "ngram_analyzer": {
          "type": "custom",
          "char_filter": ["html_strip"],
          "tokenizer": "ngram_tokenizer",
          "filter": ["cjk_width", "lowercase"]
        },
        "facet_analyzer": {
          "type": "custom",
          "char_filter": ["html_strip"],
          "tokenizer": "keyword",
          "filter": ["cjk_width", "lowercase"]
        }
      },
      "tokenizer": {
        "ngram_tokenizer": {
          "type": "nGram",
          "min_gram": 2,
          "max_gram": 3,
          "token_chars": ["letter", "digit"]
        }
      }
    }
  },
  "mappings": {
    "tweet": {
      "properties": {
        "created_at": {
          "type": "date",
          "format" : "EE MMM d HH:mm:ss Z yyyy"
        },
        "text": {
          "type": "string",
          "index": "analyzed",
          "analyzer": "ngram_analyzer"
        },
        "analyze_text": {
          "type": "string",
          "index": "not_analyzed"
        },
        "source": {
          "type": "string",
          "index": "analyzed",
          "analyzer": "facet_analyzer"
        },
        "in_reply": {
          "type": "object",
          "properties": {
            "status": {
              "type": "long"
            },
            "user_id": {
              "type": "long"
            },
            "screen_name": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "user": {
          "type": "object",
          "properties": {
            "id": {
              "type": "long"
            },
            "name": {
              "type": "string",
              "index": "not_analyzed"
            },
            "screen_name": {
              "type": "string",
              "index": "not_analyzed"
            },
            "location": {
              "type": "string"
            },
            "description": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "ngram_analyzer"
            },
            "url": {
              "type": "string"
            },
            "followers_count": {
              "type": "long"
            },
            "friends_count": {
              "type": "long"
            },
            "listed_count": {
              "type": "long"
            },
            "created_at": {
              "type": "date",
              "format" : "EE MMM d HH:mm:ss Z yyyy"
            },
            "favourites_count": {
              "type": "long"
            },
            "statuses_count": {
              "type": "long"
            },
            "lang": {
              "type": "string"
            },
            "profile_image_url": {
              "type": "string"
            },
            "profile_banner_url": {
              "type": "string"
            }
          }
        },
        "geo": {
          "type": "geo_point",
          "ignore_malformed": true
        },
        "place": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "url": {
              "type": "string"
            },
            "place_type": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "full_name": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "ngram_analyzer"
            },
            "country_code": {
              "type": "string"
            },
            "country": {
              "type": "string"
            }
          }
        },
        "retweet_count": {
          "type": "long"
        },
        "favorite_count": {
          "type": "long"
        },
        "lang": {
          "type": "string"
        },
        "hashtags": {
          "properties": {
            "text": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "facet_analyzer"
            }
          }
        },
        "user_mentions": {
          "properties": {
            "screen_name": {
              "type": "string",
              "index": "not_analyzed"
            },
            "name": {
              "type": "string",
              "index": "not_analyzed"
            },
            "id": {
              "type": "long"
            }
          }
        },
        "media": {
          "properties": {
            "id": {
              "type": "long"
            },
            "media_url_https": {
              "type": "string"
            },
            "expanded_url": {
              "type": "string"
            },
            "type": {
              "type": "string"
            }
          }
        },
        "retweeted_status": {
          "type": "object",
          "properties": {
            "created_at": {
              "type": "date",
              "format" : "EE MMM d HH:mm:ss Z yyyy"
            },
            "id": {
              "type": "long"
            },
            "text": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "ngram_analyzer"
            },
            "source": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "facet_analyzer"
            },
            "in_reply": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "long"
                },
                "user_id": {
                  "type": "long"
                },
                "screen_name": {
                  "type": "string",
                  "index": "not_analyzed"
                }
              }
            },
            "user": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "long"
                },
                "name": {
                  "type": "string",
                  "index": "not_analyzed"
                },
                "screen_name": {
                  "type": "string",
                  "index": "not_analyzed"
                },
                "location": {
                  "type": "string"
                },
                "description": {
                  "type": "string",
                  "index": "analyzed",
                  "analyzer": "ngram_analyzer"
                },
                "url": {
                  "type": "string"
                },
                "followers_count": {
                  "type": "long"
                },
                "friends_count": {
                  "type": "long"
                },
                "listed_count": {
                  "type": "long"
                },
                "created_at": {
                  "type": "date",
                  "format" : "EE MMM d HH:mm:ss Z yyyy"
                },
                "favourites_count": {
                  "type": "long"
                },
                "statuses_count": {
                  "type": "long"
                },
                "lang": {
                  "type": "string"
                },
                "profile_image_url": {
                  "type": "string"
                },
                "profile_banner_url": {
                  "type": "string"
                }
              }
            }
          }
        },
        "quoted_status": {
          "type": "object",
          "properties": {
            "created_at": {
              "type": "date",
              "format" : "EE MMM d HH:mm:ss Z yyyy"
            },
            "id": {
              "type": "long"
            },
            "text": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "ngram_analyzer"
            },
            "source": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "facet_analyzer"
            },
            "in_reply": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "long"
                },
                "user_id": {
                  "type": "long"
                },
                "screen_name": {
                  "type": "string",
                  "index": "not_analyzed"
                }
              }
            },
            "user": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "long"
                },
                "name": {
                  "type": "string",
                  "index": "not_analyzed"
                },
                "screen_name": {
                  "type": "string",
                  "index": "not_analyzed"
                },
                "location": {
                  "type": "string"
                },
                "description": {
                  "type": "string",
                  "index": "analyzed",
                  "analyzer": "ngram_analyzer"
                },
                "url": {
                  "type": "string"
                },
                "followers_count": {
                  "type": "long"
                },
                "friends_count": {
                  "type": "long"
                },
                "listed_count": {
                  "type": "long"
                },
                "created_at": {
                  "type": "date",
                  "format" : "EE MMM d HH:mm:ss Z yyyy"
                },
                "favourites_count": {
                  "type": "long"
                },
                "statuses_count": {
                  "type": "long"
                },
                "lang": {
                  "type": "string"
                },
                "profile_image_url": {
                  "type": "string"
                },
                "profile_banner_url": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment