# -*- coding: utf-8 -*-

from requests.auth import HTTPBasicAuth
import requests

def es_search(order, index):
    result = []
    if not isinstance(order, 'dict'):
        return

    url = 'http://172.21.28.64:9200/{}/_search'
    user = 'fanghuixian'
    passwd = 'fanghuixian'

    r = requests.post(url.format(index), auth=HTTPBasicAuth(user, passwd), json=order)
    if r.status_code == 200:
        result = r.json()

    return result