error while running the elasticsearch-reindexer from command prompt - elasticsearch

elasticsearch-reindex -f http://localhost:9200/artist -t http://localhost:9200/painter
Getting error as:
TypeError: Invalid hosts config. Expected a URL, an array of urls, a host config object, or an array of host config objects.
worker exited with error code: 1
Reindexing completed sucessfully.

Do you really need a plugin to do that?
curl -XPOST 'localhost:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'
{
"source": {
"index": "artist"
},
"dest": {
"index": "painter"
}
}
'
This should work just fine. More options and info here.

Related

Opendistro elasticsearch, no permissions for [ ] and User [name=admin, roles=[admin]

I try to run this command on elasticsearch server but i get error for permission.
I use opendistro for elasticsearch
curl -XPUT 'localhost:9200/_settings' -H 'Content-Type: application/json' -H 'securitytenant: Private' -u admin --insecure -d '{
"index" : {
"number_of_replicas" : 0
}
}'
{“error”:{“root_cause”:[{“type”:“security_exception”,“reason”:“no
permissions for [ ] and User [name=admin, roles=[admin],
requestedTenant=Private]”}],“type”:“security_exception”,“reason”:“no
permissions for [ ] and User [name=admin, roles=[admin],
requestedTenant=Private]”},“status”:403}
I tried also with out securitytenant but with the same error permission.
Other command's they run with success.
I have the same problem after migrating to opendistro with elasticsearch 7.
I did test creating new roles and cluster/index permissions, but didn't works.
Finally, what I did is curl a more specific url, specifying the index pattern, something like ...
curl -XPUT 'http://localhost:9200/logstash-*/_settings?pretty' -H 'Content-Type: application/json' -d '{"number_of_replicas": 0}' --insecure -u admin:...
And it works XD.
Acknowledge true.
Try with that.
Good look.

Programatically setting the read_only_allow_delete property of an index

I’m trying to execute the following line, but it throws an error (that I’m supposed to avoid by running the same code):
es.indices.put_settings(index="demo_index", body={
"blocks": {
"read_only_allow_delete": "false"
}
})
Error: elasticsearch.exceptions.AuthorizationException: AuthorizationException(403, 'cluster_block_exception', 'blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];')
It I trigger the same query by using curl, it is sucessfully executed and I don’t have the error:
curl -XPUT 'localhost:9200/demo_index/_settings' -H 'Content-Type: application/json' -d '{ "index": { "blocks": { "read_only_allow_delete": "false" } } }'
I also tried to use "null" instead of "false", but I’m getting the same result. Any idea?
I don't have enough reputation to add a comment, but have you tried wrapping the body parameter with index to match the curl command?
es.indices.put_settings(index="demo_index", body={
"index": {
"blocks": {
"read_only_allow_delete": "false"
}
}
})
With new API you can achieve this as :
import elasticsearch
def connect_elasticsearch():
_es = None
_es = elasticsearch.Elasticsearch([{'host': 'localhost', 'port': 9200}])
if _es.ping():
print('Yay Connect')
else:
print('Awww it could not connect!')
return _es
es = connect_elasticsearch()
try:
body = {"index.blocks.read_only_allow_delete": "false"}
es_index_settings = es.indices.put_settings(index="demo_index",body=body)
except elasticsearch.ElasticsearchException as exp:
print(exp)

Trigger build with parameters

Following a TC upgrade to 2018
My previous script of triggering a TC build with parameters is not working
The script we were using uses the following api:
https://[server]/httpAuth/action.html?add2Queue=[build name]&name=[param name]&value=[param value]
I'm trying to migrate to restApi
from (https://confluence.jetbrains.com/display/TCD18/REST+API#RESTAPI-QueuedBuilds):
I have tried
https://[server]/app/rest/buildQueue?locator=buildType:[build name],[param name]:[param value]
Currently I have 2 issues:
I get a build triggered successfully - but it has not been triggered
Documentation was not clear, how to I trigger the build with parameters ?
Can you please advise on how to trigger the build successfully with parameters (also could be more than 1)
Firstly you right TeamCity documentation is not clear. Respect to this link;
For triggering a build you must make POST request to this url and send buildType id through body.
http://localhost:8111/httpAuth/app/rest/buildQueue
Also you can pass configuration parameter into body.
XML body for trigger build with parameters:
<build><buildType id="YourBuildTypeId"/>
<properties><property name="PARAM1" value="VALUE1"/></properties>
</build>
JSON body for trigger build with parameters:
{
"buildType": {
"id": "YourBuildTypeId"
},
"properties": {
"property": [
{
"name": "PARAM1",
"value": "VALUE1"
},
{
"name": "PARAM2",
"value": "VALUE2"
}
]
}
}
You can use below curl script.
curl -X POST \
http://localhost:8111/httpAuth/app/rest/buildQueue \
-H 'Accept: application/json' \
-H 'Content-Type: application/xml' \
-d '<build><buildType id="YourBuildTypeId"/>
<properties><property name="PARAM1" value="VALUE1"/></properties>
</build>'

Missing newline for adding with bulk API

I want to add the following file to Elasticsearch using the bulk API:
{"_id":{"date":"01-2007","profile":"Da","dgo":"DGO_E_AIEG","consumerType":"residential"},"value":{"min":120.42509,"minKwh":0.20071,"nbItems":6.0}}
using the command
curl -XPOST -H 'Content-Type: application/json' localhost:9200/_bulk --data-binary Downloads/bob/test.json
but I got the following mistake:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\n]"}],"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\n]"},"status":400}
NB: The file clearly has a empty line at the end
In the docs it says:
NOTE: the final line of data must end with a newline character \n.
There is an example above that of what the document is expected to look like. https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html. Perhaps adding \n at the end of each line would fix the issue.
UPDATE:
There might be something wrong with the way you have placed your data into your JSON file. For example, the following data is in example.json:
{ "index" : { "_index" : "example", "_type" : "doc", "_id" : "1" } }
{ "field1" : "value1" }
<space here>
When running the following curl command, it works:
curl -X POST -H "Content-Type: application/x-ndjson" localhost:9200/_bulk --data-binary "#example.json"
It could be that you're not including something important in your JSON file, or you don't have "#your_file.json", or like the other poster mentioned, you don't have the content-type as application/x-ndjson.
The answer is very simple
{ "index":{ "_index":"schools_gov", "_type":"school", "_id":"1" } }
{ "name":"Model School", "city":"Hyderabad"}
{ "index":{ "_index":"schools_gov", "_type":"school", "_id":"2" } }
{ "name":"Government School", "city":"Pune"}
is not going to work but the below json will work
{ "index":{ "_index":"schools_gov", "_type":"school", "_id":"1" } }
{ "name":"Model School", "city":"Hyderabad"}
{ "index":{ "_index":"schools_gov", "_type":"school", "_id":"2" } }
{ "name":"Government School", "city":"Pune"}
//Give a new line here. Not '\n' but the actual new line.
The HTTP command would be POST http://localhost:9200/schools_gov/_bulk
As the error states, you simply need to add a new line to the end of the file.
If you are on a *nix system, you can do this:
echo "\n" >> Downloads/bob/test.json
Also, as explained in the documentation https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html, the Content-Type should be application/x-ndjson
When sending requests to this endpoint the Content-Type header should
be set to application/x-ndjson
So the command should be:
curl -XPOST -H 'Content-Type: application/x-ndjson' localhost:9200/_bulk --data-binary Downloads/bob/test.json
The error message is very confusing. I typed -data-binary and got the same message. The message sent me to completely wrong direction.

Cannot turn Elasticsearch dynamic mapping on

I disabled dynamic mapping with
curl -XPUT 'localhost:9200/_template/template_all?pretty' -H 'Content-Type: application/json' -d' { "template": "*", "order":0, "settings": { "index.mapper.dynamic": false }}'
I wanted to turn it back on with
curl -XPUT 'localhost:9200/_template/template_all?pretty' -H 'Content-Type: application/json' -d' { "template": "*", "order":0, "settings": { "index.mapper.dynamic": true }}'
It has confirmed it as true, but when I try to have logstash send information to it, in logstash error logs I get back-
"reason"=>"trying to auto create mapping, but dynamic mapping is disabled"
How do I actually turn dynamic mapping back on?
Looks like index for logstash was created with old template (before you update template). Because when you update you template only new indexes will have updated mapping and settings.
Check is index exists:
curl -XGET 'localhost:9200/LOGSTASH_INDEX_NAME_HERE'
If index exists and you can delete this index - do it. After this when logstash will try to send something - index will be created with the new mapping.

Resources