我有一个非常简单的问题:
我想将多个文档更新为elasticsearch.有时文件已经存在但有时却不存在.我不想使用get请求来检查文档是否存在(这会降低我的性能).我想直接使用我的更新请求来直接索引文档,如果它还不存在的话.
我知道在更新文档时我们可以使用upsert创建一个不存在的字段,但这不是我想要的.如果文档不存在,我想索引该文档.我不知道upsert是否可以做到这一点.
你能给我一些解释吗?
提前致谢!
我正在使用elasticsearch 1.1.
通常在这个版本中,嵌套文档上的过滤器应该可以工作.
虽然,我试图这样做,但我收到以下错误:
failures: [
{
index: test
shard: 4
reason: BroadcastShardOperationFailedException[[test][4] ]; nested: PercolateException[failed to percolate]; nested: ElasticsearchIllegalArgumentException[Nothing to percolate];
}
]
Run Code Online (Sandbox Code Playgroud)
我有以下过滤器(对不起elasticsearch头删除了我的所有报价):
{
_index: test
_type: .percolator
_id: 27
_version: 1
_score: 1
_source: {
query: {
filtered: {
query: {
match_all: { }
}
filter: {
nested: {
filter: {
term: {
city: london
}
}
path: location
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在尝试渗透此文档时,我收到错误:
{
...
"location": {
"date": "2014-05-05T15:07:58",
"namedplaces": {
"city": "london"
} …Run Code Online (Sandbox Code Playgroud) 我正在使用Java API对Elasticsearch进行CRUD操作。
我有一个带有嵌套字段的类型,我想更新此字段。
这是我对类型的映射:
"enduser": {
"properties": {
"location": {
"type": "nested",
"properties":{
"point":{"type":"geo_point"}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当然,我的最终用户类型将具有其他参数。
现在,我想将此文档添加到我的嵌套字段中:
"location":{
"name": "London",
"point": "44.5, 5.2"
}
Run Code Online (Sandbox Code Playgroud)
我在文档中搜索有关如何更新嵌套文档的信息,但找不到任何东西。例如,我在字符串中具有先前的JSON对象(我们将此字符串称为json)。我尝试了以下代码,但似乎无法正常工作:
params.put("location", json);
client.prepareUpdate(index, ElasticSearchConstants.TYPE_END_USER,id).setScript("ctx._source.location = location").setScriptParams(params).execute().actionGet();
Run Code Online (Sandbox Code Playgroud)
我有来自Elasticsearch的解析错误。有人知道我在做什么错吗?