gpt4 book ai didi

python - 在 Elasticsearch 中过滤特定字段上的查询

转载 作者:行者123 更新时间:2023-12-03 01:03:17 27 4
gpt4 key购买 nike

我有这样的文件

  {
_index: "logstash-2015.11.30",
_type: "hadoopgeneric",
_id: "AVFVsF6ypMu_z_qvIUgL",
_score: null,
_source: {
@timestamp: "2015-11-30T00:00:00.017Z",
message: "selector : 48 - Element found for using multiple selectors using query .js-product-brand.product-brand",
@version: "1",
host: "ip-x-x-x-x",
path: "/logs/stats/container/application_1448508514184_0178/container_e06_1448508514184_0178_01_003568/stderr",
type: "hadoopgeneric",
thread_id: "15119",
thread_name: "MainThread",
component_name: "Page",
severity: "DEBUG",
env: "STG",
role: "spider",
ip: "x.x.x.x",
tags: [
"processed"
]
},
}

我必须过滤其中包含路径 /logs/stats/container/application_1448508514184_0178/container_e06_1448508514184_0178_01_003568/stderr的那些文档(特别是在 path字段中)

我尝试了此一般搜索查询 http://localhost:9200/logstash-*/_search?pretty=true&q="/logs/stats/container/application_1448508514184_0178/container_e06_1448508514184_0178_01_003568/stderr"&sort=@timestamp&size=100000
它给了我结果,但现在我正在考虑尝试通过像这样触发此查询来仅在 path字段中进行搜索(此查询中没有任何结果)- http://localhost:9200/logstash-*/_search?pretty=true&q="path: /logs/stats/container/application_1448508514184_0178/container_e06_1448508514184_0178_01_003568/stderr"&sort=@timestamp&size=100000
我正在 flex 搜索中浏览这份文档 Term Query。但是我不确定如何在 flex 搜索中传递诸如post参数之类的查询。我正在使用python库发出发布请求以进行 flex 搜索

以下是我到目前为止尝试过的
esurl = http://localhost:9200/logstash-*/_search
r = requests.post(esurl,data={"term":{'path':'/logs/stats/container/application_1448508514184_0178/container_e06_1448508514184_0178_01_003568/stderr'}})
r.text
{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[5D_RNDQPRf6xyLO1suIoCA][logstash-2015.11.30][0]: RemoteTransportException[[ip-x-x-x-x-elkstorage][inet[/x.x.x.x:9300]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[logstash-2015.11.30][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticsearchParseException[Failed to derive xcontent]; }{[o8jLb8P5SWOfsCo78eUlHg][logstash-2015.12.01][0]: RemoteTransportException[[ip-x-x-x-x-elkstorage][inet[/x.x.x.x:9300]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[logstash-2015.12.01][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticsearchParseException[Failed to derive xcontent];}

最佳答案

q参数似乎错误("字符位置错误),请尝试以下操作:

http://localhost:9200/logstash-*/_search?pretty=true&q=path:"/logs/stats/container/application_1448508514184_0178/container_e06_1448508514184_0178_01_003568/stderr"&sort=@timestamp&size=100000

另一方面,查询一词有效,但必须在 query键之内,例如:
import requests
import json

esurl = "http://localhost:9200/logstash-*/_search"
r = requests.post(esurl,data=json.dumps({"query": {"term":{'path':'/logs/stats/container/application_1448508514184_0178/container_e06_1448508514184_0178_01_003568/stderr'}}}))
r.text

关于python - 在 Elasticsearch 中过滤特定字段上的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34515498/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com