How to use the elasticsearch5.Elasticsearch function in elasticsearch5

To help you get started, we’ve selected a few elasticsearch5 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github odanado / slack-search / app / main.py View on Github external
ELASTICSEARCH_URL = os.environ['ELASTICSEARCH_URL']

POSTGRES_PASSWORD = os.environ['POSTGRES_PASSWORD']

app = flask.Flask(__name__)
cors = CORS(app, resources={
    r"/validate_token": {"origins": CLIENT_URL},
    r"/search": {"origins": CLIENT_URL}
})

app.config['SQLALCHEMY_DATABASE_URI'] = \
    'postgresql://postgres:{}@db'.format(POSTGRES_PASSWORD)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db = SQLAlchemy(app)

es = Elasticsearch([ELASTICSEARCH_URL])


class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    token = db.Column(db.String(512), index=True)
    secret = db.Column(db.String(36), unique=True)

    def to_dict(self):
        return dict(
            id=self.id,
            token=self.token,
            secret=self.secret
        )

    def __init__(self, token, secret):
github shirosaidev / stocksight / sentiment.py View on Github external
/$$$$$$$ /$$$$$$    /$$$$$$   /$$$$$$$| $$   /$$  /$$$$$$$ /$$  /$$$$$$ | $$$$$$$  /$$$$$$  
 /$$_____/|_  $$_/   /$$__  $$ /$$_____/| $$  /$$/ /$$_____/| $$ /$$__  $$| $$__  $$|_  $$_/  
|  $$$$$$   | $$    | $$  \ $$| $$      | $$$$$$/ |  $$$$$$ | $$| $$  \ $$| $$  \ $$  | $$    
 \____  $$  | $$ /$$| $$  | $$| $$      | $$_  $$  \____  $$| $$| $$  | $$| $$  | $$  | $$ /$$
 /$$$$$$$/  |  $$$$/|  $$$$$$/|  $$$$$$$| $$ \  $$ /$$$$$$$/| $$|  $$$$$$$| $$  | $$  |  $$$$/
|_______/    \___/   \______/  \_______/|__/  \__/|_______/ |__/ \____  $$|__/  |__/   \___/  
                                                                 /$$  \ $$                    
                       :) = +$   :( = -$                        |  $$$$$$/                    
                                                                 \______/  v%s
    Join the StockSight website https://stocksight.diskoverspace.com
        \033[0m""" % (color, STOCKSIGHT_VERSION)
        print(banner + '\n')

    if not args.noelasticsearch:
        # create instance of elasticsearch
        es = Elasticsearch(hosts=[{'host': elasticsearch_host, 'port': elasticsearch_port}],
                   http_auth=(elasticsearch_user, elasticsearch_password))

        # set up elasticsearch mappings and create index
        mappings = {
            "mappings": {
                "tweet": {
                    "properties": {
                        "author": {
                            "type": "string",
                            "fields": {
                                "keyword": {
                                    "type": "keyword"
                                }
                            }
                        },
                        "location": {
github odanado / slack-search / es-python / run.py View on Github external
import os
import time
from datetime import datetime

import click
from logzero import logger
from slackclient import SlackClient
from elasticsearch5 import Elasticsearch, helpers

from utils import convert_message
from config import INDEX_NAME, TYPE_NAME

ELASTICSEARCH_URL = os.environ['ELASTICSEARCH_URL']
es = Elasticsearch([ELASTICSEARCH_URL])

slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)


@click.group()
def cmd():
    pass


def fetch_message(es, channel, timestamp):
    body = {
        "query": {
            "bool": {
                "must": [
                    {
github odanado / slack-search / es-python / preprocess.py View on Github external
import os
import json
from pathlib import Path

import click
from elasticsearch5 import Elasticsearch, helpers

from utils import convert_message
from config import INDEX_NAME, TYPE_NAME

ELASTICSEARCH_URL = os.environ['ELASTICSEARCH_URL']
es = Elasticsearch([ELASTICSEARCH_URL])


@click.group()
def cmd():
    pass


def parse_file(fname, channel):
    results = []
    for data in json.load(fname.open()):
        data = convert_message(data)
        if data is None:
            continue

        data['channel'] = channel
        results.append(data)
github 0Kee-Team / WatchAD / tools / database / ElsaticHelper.py View on Github external
def __init__(self):
        self.es = Elasticsearch(ElasticConfig.uri)
        self._multi_search_results = []
        self.bulk_task_queue = []
        self.bulk_last_time = datetime_now_obj()
github cisco / mindmeld / mindmeld / components / _elasticsearch_helpers.py View on Github external
def create_es_client(es_host=None, es_user=None, es_pass=None):
    """Creates a new Elasticsearch client

    Args:
        es_host (str): The Elasticsearch host server
        es_user (str): The Elasticsearch username for http auth
        es_pass (str): The Elasticsearch password for http auth
    """
    es_host = es_host or os.environ.get("MM_ES_HOST")
    es_user = es_user or os.environ.get("MM_ES_USERNAME")
    es_pass = es_pass or os.environ.get("MM_ES_PASSWORD")

    try:
        http_auth = (es_user, es_pass) if es_user and es_pass else None
        es_client = Elasticsearch(es_host, http_auth=http_auth)
        return es_client
    except ElasticsearchException:
        raise KnowledgeBaseError
    except ImproperlyConfigured:
        raise KnowledgeBaseError
github shirosaidev / stocksight / stockprice.py View on Github external
from elasticsearch5 import Elasticsearch
except ImportError:
    from elasticsearch import Elasticsearch
from random import randint

# import elasticsearch host
from config import elasticsearch_host, elasticsearch_port, elasticsearch_user, elasticsearch_password

from sentiment import STOCKSIGHT_VERSION
__version__ = STOCKSIGHT_VERSION

# url to fetch stock price from, SYMBOL will be replaced with symbol from cli args
url = "https://query1.finance.yahoo.com/v8/finance/chart/SYMBOL?region=US&lang=en-US&includePrePost=false&interval=2m&range=5d&corsDomain=finance.yahoo.com&.tsrc=finance"

# create instance of elasticsearch
es = Elasticsearch(hosts=[{'host': elasticsearch_host, 'port': elasticsearch_port}],
                   http_auth=(elasticsearch_user, elasticsearch_password))

class GetStock:

    def get_price(self, url, symbol):
        import re

        while True:

            logger.info("Grabbing stock data for symbol %s..." % symbol)

            try:

                # add stock symbol to url
                url = re.sub("SYMBOL", symbol, url)
                # get stock data (json) from url