URI中的Json对象



我正试图在python中查询我的弹性搜索服务器,如果我在python(search(((脚本中像下面这样硬编码url和查询字符串,工作正常,没有问题。如果我想将这些url和查询存储在一个单独的xml文件(属性文件(中。我没有得到结果,相反,我得到了以下错误:

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

这是我的代码,我正在使用

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属性文件如下:

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

知道我错过了什么吗?,非常感谢

我自己很少锻炼就能搞定。万一有人在找:

我刚用了下面的

response=requests.post(url,auth=(用户,密码(,verify=False,json=json.loads(查询((

最新更新