Json object in URI

user8781522

I am trying to query my elastic search server in python, If I hard coded the url and query string like below in my python (search()) script working fine no issues. If I want to store those url and query in a separate xml file (property file). I'm not getting the results instead I got the below error:

text    '{"error":{"root_cause":[{"type":"parsing_exception","reason":"Expected [START_OBJECT] but found [VALUE_STRING]","line":1,"col":1}],"type":"parsing_exception","reason":"Expected [START_OBJECT] but found [VALUE_STRING]","line":1,"col":1},"status":400}' str

Here is my code I am using

def search():          
        url="http://0.0.0.0/logstash-pse*/_search/"
        query={  "size": 0,  "aggs": {    "2": {      "date_histogram": {        "field": "@timestamp",        "interval": "30m",        "time_zone": "America/Chicago",        "min_doc_count": 1      },      "aggs": {        "3": {          "terms": {            "field": "queryname.keyword",            "size": 100,            "order": {              "1.90": "desc"            }          },          "aggs": {            "1": {              "percentiles": {                "field": "queryResponseTime",                "percents": [                  90                ],                "keyed": "false"              }            }          }        }      }    }  },  "query": {    "bool": {      "must": [        {          "query_string": {            "query": "path: \"/store_locator/\"",            "analyze_wildcard": "true"          }        },        {          "query_string": {            "analyze_wildcard": "true",            "query": "*"          }        },        {          "range": {            "@timestamp": {              "gte": 1527181463371,              "lte": 1527267863371,              "format": "epoch_millis"            }          }        }      ],      "must_not": []    }  },  "highlight": {    "pre_tags": [      "@kibana-highlighted-field@"    ],    "post_tags": [      "@/kibana-highlighted-field@"    ],    "fields": {      "*": {        "highlight_query": {          "bool": {            "must": [              {                "query_string": {                  "query": "path: \"/store_locator/\"",                  "analyze_wildcard": "true",                  "all_fields": "true"                }              },              {                "query_string": {                  "analyze_wildcard": "true",                  "query": "*",                  "all_fields": "true"                }              },              {                "range": {                  "@timestamp": {                    "gte": 1527181463371,                    "lte": 1527267863371,                    "format": "epoch_millis"                  }                }              }            ],            "must_not": []          }        }      }    },    "fragment_size": 2147483647  },  "_source": {    "excludes": []  },  "version": "true"}          

        response = requests.post(url, auth=(user, password), verify=False,json=query) 

XML property file I am using like the below:

<custom>
<url>the above url goes here</url>
<query> above query </query>
</custom>

Any idea what I am missing?, Much appreciated

user8781522

Able to figure it out with few exercise on my own. In case if someone is looking for:

I just used the below

response = requests.post(url, auth=(user, password), verify=False,json=json.loads(query))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related