Skip to content

Instantly share code, notes, and snippets.

@derickson
derickson / app_script.gs
Created December 10, 2025 14:54
Polling a Gmail applied filter label as ingest queue for Elasticsearch
// polling code adapted from: https://gist.github.com/benbjurstrom/00cdfdb24e39c59c124e812d5effa39a
// Settings for polling Gmail
const GMAIL_LABEL = "STATUSREPORT";
const PAGE_SIZE = 25;
// Settings for Elasticsearch
const ELASTICSEARCH_HOST = "https://xxxxxxxx.elastic.cloud:443";
const ELASTIC_API_KEY_BASE64 = "xxxxxxxx==";
## Install the required packages
## pip install -qU elasticsearch openai
import os
from elasticsearch import Elasticsearch
from openai import OpenAI
es_client = Elasticsearch(
"undefined",
api_key=os.environ["ES_API_KEY"]
)
@derickson
derickson / logstash-bikehare-status.conf
Last active March 10, 2021 14:26
Logstash config for http_poller pulling of DC Capital bikeshare data and doing an XML split of the contents.
## Example of pulling data from DC Capital bikeshare to Elasticsearch in real time
## HTTP Poller -> XML Splitting -> Elasticsearch
input {
## pull data from Capital Bikeshare every 60 seconds
http_poller {
urls => {
bikeshare_dc => "https://www.capitalbikeshare.com/data/stations/bikeStations.xml"
}
request_timeout => 30
@derickson
derickson / mongoToES.js
Created July 16, 2015 15:18
Example of NodeJS Loop of Mongo to Elasticsearch
// npm install elasticsearch
// setup nodejs client for elasticsearch
// documentation: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html
var elasticsearch = require('elasticsearch');
var EsClient = new elasticsearch.Client({
host: 'localhost:9200',
log: 'info'
});
## 1) Pull all records from index named fedeastsql
POST /_xpack/sql?format=txt
{
"query": "SELECT * FROM fedeastsql"
}
## 2) List all columns and datatype of this index
#!/bin/python3
import json
import moment
from elasticsearch import helpers
from elasticsearch import Elasticsearch
esConnString = 'http://elastic:changeme@localhost:9200'
esTo = Elasticsearch([esConnString],request_timeout=100)
PUT my_index
{
"mappings": {
"properties": {
"securityTags": {
"type": "keyword",
"fields": {
"length": {
"type": "token_count",
"analyzer": "standard"
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
def prettyPrint(doc):
print(json.dumps(doc, indent=4, sort_keys=True))
{
"bool": {
"should": [
[
{
"bool": {
"must": [
[
{
"term": {
### EXAMPLE SEARCH: Has Spotify run in the last 30 seconds?
GET /topbeat-*/_search
{
"query": {
"bool": {
"must": [
{"term": {
"proc.name": {
"value": "Spotify"