如何从弹性搜索索引中删除旧数据,因为索引每天都会插入大量数据.
如何使用python查询检查索引是否存在?
我将我的索引作为在查询外部分配的变量传递为: -
i=int(datetime.datetime.now().strftime('%d'))+1
indextring="index"
for m in range (i-10,i):
d = datetime.datetime(2016, 10, m, 18, 00).strftime('%Y-%m-%d')
index1=datestring+d
subfix="_"+datetime.datetime(2016, 10, m, 18, 00).strftime('%Y-%m-%d')
es=Elasticsearch(['localhost:9200'])
res = **es.search(index='{0}'.format(index1)**, doc_type="log",size=10000, from_=0, body={ "query": {
"match": {
....Match condition follows
}
}
}})
Run Code Online (Sandbox Code Playgroud)
现在,某些索引在特定日期不存在,但我希望该过程无论如何都要运行.当索引不存在时,我收到以下错误 - >
elasticsearch.exceptions.NotFoundError:TransportError(404,u'index_not_found_exception')
我不确定异常处理在elasticsearch中是如何工作的.
python elasticsearch elasticsearch-plugin elasticsearch-net elasticsearch-2.0
我正在使用olivere的弹性Go库来运行弹性查询 - https://godoc.org/github.com/olivere/elastic#NestedQuery
我正在尝试查询的数据如下所示:
"_source": {
"field1": "randVal1",
"field2": "randVal2",
"nestedfield": {
"ind1": "val1"
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试nestedfield使用NestedQueryElastic Go库中的调用运行查询,如下所示:
aquery := elastic.NewTermQuery("ind1", "val1")
query := elastic.NestedQuery("nestedfield", aquery)
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误说明:
转换为NestedQuery的参数太多了
我试图检索所有的文件,其中ind1的nestedfield是val1.非常感谢构建此查询的任何帮助.
编辑:
我将其更改为NewNestedQuery,现在它没有给出错误.但是,它不会返回任何结果,即使该文档存在于索引中并且我能够查询非嵌套字段.
我试过这个:
aquery := elastic.NewTermQuery("ind1", "val1")
query := elastic.NewNestedQuery("nestedfield", aquery)
Run Code Online (Sandbox Code Playgroud)
还有这个:
query := elastic.NewNestedQuery("nestedfield", elastic.NewMatchQuery("nestedfield.ind1", "val1"))
Run Code Online (Sandbox Code Playgroud)
但他们都给出了0结果.知道我做错了什么吗?
编辑#2
映射是:
"field1": { "type": "string" },
"field2": { "type": "string" },
"nestedfield": {
"type": "nested"
}
Run Code Online (Sandbox Code Playgroud)
最终起作用的是:
query := elastic.NewMatchQuery("nestedfield.ind1", "val1")
Run Code Online (Sandbox Code Playgroud)
我能够在'nestedfield'中添加其他字段并执行以下查询: …
我在Rails 4中通过elasticsearch-rails使用ElasticSearch(https://github.com/elasticsearch/elasticsearch-rails)
我有一个用户模型,带有电子邮件属性.
我正在尝试使用文档中描述的'uax_url_email'标记生成器:
class User < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
settings analysis: { analyzer: { whole_email: { tokenizer: 'uax_url_email' } } } do
mappings dynamic: 'false' do
indexes :email, analyzer: 'whole_email'
end
end
end
Run Code Online (Sandbox Code Playgroud)
我按照wiki(https://github.com/elasticsearch/elasticsearch-rails/wiki)和elasticsearch-model docs(https://github.com/elasticsearch/elasticsearch-rails/wiki)中的示例进行了操作.
它不起作用.如果我直接查询elasticsearch:
curl -XGET 'localhost:9200/users/_mapping
Run Code Online (Sandbox Code Playgroud)
它返回:
{
"users": {
"mappings": {
"user": {
"properties": {
"birthdate": {
"type": "date",
"format": "dateOptionalTime"
},
"created_at": {
"type": "date",
"format": "dateOptionalTime"
},
"email": {
"type": "string"
},
"first_name": {
"type": …Run Code Online (Sandbox Code Playgroud) ruby ruby-on-rails elasticsearch ruby-on-rails-4 elasticsearch-plugin
我kibana-4在我的Linux机器上安装了.我的要求是我想在我的kibana主页中删除保存搜索字段等选项,我想通过我自己定制的菜单栏更改kibana的顶级菜单栏.这是我想做什么的快照.

我正在使用docker-compose来启动3个应该在副本集中的MongoDB服务器.
我首先启动3个MongoDB服务器,然后配置副本集.这就是我在bash脚本中执行副本集配置的方法:
mongo --host 127.0.0.1:27017 <<EOF
var cfg = {
"_id": "rs",
"version": 1,
"members": [
{
"_id": 0,
"host": "127.0.0.1:27017",
"priority": 1
},
// snip...
]
};
rs.initiate(cfg);
rs.reconfig(cfg)
EOF
Run Code Online (Sandbox Code Playgroud)
在这里,我试图使用docker-compose复制配置副本集.
# docker-compose.yml
mongosetup:
image: mongo:3.0
links:
- mongo1:mongo1
command: echo 'var cfg = { "_id": "rs", "version": 1, "members": [ { "_id": 0, "host": "127.0.0.1:27017", "priority": 1 }, { "_id": 1, "host": "mongo2:27017", "priority": 1 },{ "_id": 2, "host": "mongo2:27017", "priority": 1 } ] …Run Code Online (Sandbox Code Playgroud) mongodb elasticsearch docker elasticsearch-plugin docker-compose
这是我的要求:
POST /_bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{"firstname":"first_name1","lastname":"last_name1"},
{"firstname":"first_name2","lastname":"last_name2"},
{"firstname":"first_name3","lastname":"last_name3"}}
Run Code Online (Sandbox Code Playgroud)
这是错误:
Run Code Online (Sandbox Code Playgroud){ "error": "IllegalArgumentException[Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found[VALUE_STRING]]","状态":500}
基本上,每个文档都是{"firstname":___,"lastname":____}我不想将它们包装到父字段中.我从根本上缺少什么?
我在debian jessie上安装elasticsearch 1.7.3.它使用默认配置文件并正常工作.但是当我调用sudo /usr/share/elasticsearch/bin/plugin它时会返回一个错误:
Exception in thread "main" org.elasticsearch.env.FailedToResolveConfigException: Failed to resolve config path ["/usr/share/elasticsearch/config/elasticsearch.yml"], tried file path ["/usr/share/elasticsearch/config/elasticsearch.yml"], path file ["/usr/share/elasticsearch/config"/"/usr/share/elasticsearch/config/elasticsearch.yml"], and classpath
at org.elasticsearch.env.Environment.resolveConfig(Environment.java:291)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareSettings(InternalSettingsPreparer.java:95)
at org.elasticsearch.plugins.PluginManager.main(PluginManager.java:396)
Run Code Online (Sandbox Code Playgroud)
文件/usr/share/elasticsearch/config/elasticsearch.yml存在,我可以用nano打开他.
有/ etc/default/elasticsearch文件:
# Start Elasticsearch automatically
START_DAEMON=true
# Run Elasticsearch as this user ID and group ID
#ES_USER=elasticsearch
#ES_GROUP=elasticsearch
# Heap Size (defaults to 256m min, 1g max)
#ES_HEAP_SIZE=2g
# Heap new generation
#ES_HEAP_NEWSIZE=
# max direct memory
#ES_DIRECT_SIZE=
# Maximum number of open files, …Run Code Online (Sandbox Code Playgroud) 首先,我想设置ES的默认分析器,但失败了.然后根据其他问题和网站,我试图设置一个索引的默认分析器.但也有一些问题.
我已经配置了ik分析器,我可以设置一些字段的分析器,这是我的命令:
curl -XPUT localhost:9200/test
curl -XPUT localhost:9200/test/test/_mapping -d'{
"test":{
"properties":{
"name":{
"type":"string",
"analyzer":"ik"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
并得到消息:
{"acknowledged":true}
Run Code Online (Sandbox Code Playgroud)
它也符合我的愿望.
但是,如果我尝试设置索引的默认分析器:
curl -XPOST localhost:9200/test1?pretty -d '{ "index":{
"analysis" : {
"analyzer" : {
"default" : {
"type" : "ik"
}
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
我会收到错误消息:
{
"error" : {
"root_cause" : [ {
"type" : "index_creation_exception",
"reason" : "failed to create index"
} ],
"type" : "illegal_argument_exception",
"reason" : "no default analyzer configured"
},
"status" : 400
}
Run Code Online (Sandbox Code Playgroud)
太奇怪了,不是吗?期待您对此问题的看法.谢谢!:)
我已经安装了 elasticsearch 版本2.3.2。我必须添加index和type到弹性搜索。在我使用 sense 插件来实现这一点之前。但是该插件已从网上商店中删除。请给出建议。