有没有人有如何使用更新的例子?它的记录在这里,但文档是不清楚,不包括工作的例子.我尝试过以下方法:
coll = Elasticsearch()
coll.update(index='stories-test',doc_type='news',id=hit.meta.id,
body={"stanford": 1, "parsed_sents": parsed })
Run Code Online (Sandbox Code Playgroud)
我明白了
elasticsearch.exceptions.RequestError:
TransportError(400, u'ActionRequestValidationException[Validation Failed: 1: script or doc is missing;]')
Run Code Online (Sandbox Code Playgroud)
我想使用部分文档进行更新,但更新方法不会使用任何名为"doc"或"document"的参数.
我可以在curl命令中设置索引的映射,如下所示:
{
"mappings":{
"logs_june":{
"_timestamp":{
"enabled":"true"
},
"properties":{
"logdate":{
"type":"date",
"format":"dd/MM/yyy HH:mm:ss"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我需要在python中使用elasticsearch客户端创建该索引并设置映射..这是什么方式?我试过下面的事情,但没有工作:
self.elastic_con = Elasticsearch([host], verify_certs=True)
self.elastic_con.indices.create(index="accesslog", ignore=400)
params = "{\"mappings\":{\"logs_june\":{\"_timestamp\": {\"enabled\": \"true\"},\"properties\":{\"logdate\":{\"type\":\"date\",\"format\":\"dd/MM/yyy HH:mm:ss\"}}}}}"
self.elastic_con.indices.put_mapping(index="accesslog",body=params)
Run Code Online (Sandbox Code Playgroud) 我遇到了弹性搜索查询的问题.我希望能够对结果进行排序,但elasticsearch忽略了排序标记.在这里我的查询:
{
"sort": [{
"title": {"order": "desc"}
}],
"query":{
"term": { "title": "pagos" }
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我删除查询部分并且我只发送排序标记时,它可以工作.任何人都能指出我正确的方法吗?
我也试过以下查询,这是我的完整查询:
{
"sort": [{
"title": {"order": "asc"}
}],
"query":{
"bool":{
"should":[
{
"match":{
"title":{
"query":"Pagos",
"boost":9
}
}
},
{
"match":{
"description":{
"query":"Pagos",
"boost":5
}
}
},
{
"match":{
"keywords":{
"query":"Pagos",
"boost":3
}
}
},
{
"match":{
"owner":{
"query":"Pagos",
"boost":2
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
设置
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram",
"min_gram": 3,
"max_gram": 15, …Run Code Online (Sandbox Code Playgroud) 我正在尝试基于文档属性的状态更改进行批量更新.创建工作正常,但批量是吓坏了.我收到"脚本或文档丢失"效果的错误,但一切看起来都不错.
以下是我尝试批量更新的方法:
frequency_cleared = [
{
"_id": result['_id'],
"_type": "the-type",
"_index": "the-index",
"_source": result['_source'],
"_op_type": 'update'
}
for result in search_results['hits']['hits']
]
Run Code Online (Sandbox Code Playgroud)
我在迭代结果的原因是因为我在列表中使用了一个if理解,但是因为我能够看到结果,所以我知道这不是问题.我无法显示结果,不得不更改属性名称,因为这是我工作的公司.
这是追溯:
Elasticsearch.exceptions.RequestError:
TransportError(400, 'action_request_validation_exception',
'Validation Failed: 1: script or doc is missing...')
Run Code Online (Sandbox Code Playgroud)
省略号表示它显示列表中每个元素失败的相同错误.
我正在尝试使用elasticsearch-dsl实现多重索引方法.基本上有两个步骤:
1.创建别名:
PUT /tweets_1/_alias/tweets_search
PUT /tweets_1/_alias/tweets_index
Run Code Online (Sandbox Code Playgroud)
2.必要时更改别名:
POST /_aliases
{
"actions": [
{ "add": { "index": "tweets_2", "alias": "tweets_search" }},
{ "remove": { "index": "tweets_1", "alias": "tweets_index" }},
{ "add": { "index": "tweets_2", "alias": "tweets_index" }}
]
}
Run Code Online (Sandbox Code Playgroud)
我只能使用elasticsearch-py(而不是dsl)实现第1步:
from elasticsearch.client import IndicesClient
IndicesClient(client).("tweets_1", "tweets_search")
IndicesClient(client).("tweets_1", "tweets_index")
Run Code Online (Sandbox Code Playgroud)
我不知道如何为第2步做到这一点.那么,elasticsearch-dsl(或者至少在elasticsearch-py中)的等价物是什么?
因此,我们在 Django 项目中使用elasticsearch,并且使用elasticsearch-dsl python 库。
我们在生产中遇到以下错误:
ConflictError(409, '{"took":7,"timed_out":false,"total":1,"deleted":0,"batches":1,"version_conflicts":1,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[{"index":"events","type":"_doc","id":"KJ7SpWsBZnen1jNBRWWM","cause":{"type":"version_conflict_engine_exception","reason":"[KJ7SpWsBZnen1jNBRWWM]: version conflict, required seqNo [1418], primary term [1]. current document has seqNo [1419] and primary term [1]","index_uuid":"2-fSZILVQzuJE8KVmpLFXQ","shard":"0","index":"events"},"status":409}]}')
Run Code Online (Sandbox Code Playgroud)
并具有更好的格式:
{
"took": 7,
"timed_out": false,
"total": 1,
"deleted": 0,
"batches": 1,
"version_conflicts": 1,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1.0,
"throttled_until_millis": 0,
"failures": [
{
"index": "events",
"type": "_doc",
"id": "KJ7SpWsBZnen1jNBRWWM",
"cause": {
"type": "version_conflict_engine_exception",
"reason": "[KJ7SpWsBZnen1jNBRWWM]: version conflict, required seqNo [1418], primary term [1]. current document has …Run Code Online (Sandbox Code Playgroud) python django elasticsearch elasticsearch-dsl elasticsearch-py
我有一个足够大的数据集,我想对 AWS OpenSearch 中的 JSON 对象进行批量索引。
我看不到如何使用以下任何一个来实现此目的:boto3、awswrangler、opensearch-py、elasticsearch、elasticsearch-py。
有没有办法在不直接使用 python 请求(PUT/POST)的情况下做到这一点?
请注意,这不适用于:ElasticSearch、AWS ElasticSearch。
非常感谢!
python opensearch elasticsearch-py aws-data-wrangler amazon-opensearch
在 elasticsearch 中进行搜索操作时,我希望过滤掉元数据并在响应中仅返回“_source”。我可以通过以下方式通过“搜索”实现相同的目标:
out1 = es.search(index='index.com', filter_path=['hits.hits._id', 'hits.hits._source'])
但是当我用 scan 方法做同样的事情时,它只返回一个空列表:
out2 = helpers.scan(es, query, index='index.com', doc_type='2016-07-27',filter_path= ['hits.hits._source'])
问题可能与我处理“扫描”方法响应的方式有关,或者与我将值传递给 filter_path 的方式有关。为了检查输出,我将 out2 解析为一个列表。
我正在尝试查找我的索引/文档类型中的最后 30 条条目
我什么也没尝试,我已经没有想法了!
我当前的方法是找到过去 5 分钟内的所有结果,然后过滤结果并抓取最后 30 个条目,但这比正确的方法慢。
s = Search(using=es, index="history", doc_type=p)
.filter('range', timestamp={'gte': mins})
.extra(size=1000)
Run Code Online (Sandbox Code Playgroud)
我已经尝试过
s = Search(using=es, index="history", doc_type=p)
.sort("timestamp", {'order': "desc"})
.extra(size=30)
Run Code Online (Sandbox Code Playgroud) 我正在使用ElasticSearch批量Python API,它是否同时提供同步和异步api?