Error trying to simulate a pipeline - elasticsearch

I'm trying to create a gsub pipeline, but before I do I'm trying to simulate it by following the many examples on the internet. Here's my code:
PUT _ingest/pipeline/removescript/_simulate
{
"pipeline" :{
"description": "remove script",
"processors": [
{ "gsub" :{
"field": "content",
"pattern": "(?:..)[^<%]+[^%>](?:..)",
"replacement": ""
}
}]
},
"docs": [
{
"_id": "tt",
"_source": {
"content": "leave <% remove me %> Me"
}
}]
}
However when I run it I receive the following error:
No handler found for uri [/_ingest/pipeline/removescript/_simulate] and method [PUT]
If I change the PUT line to be:
PUT _ingest/pipeline/_simulate or PUT _ingest/pipeline/removescript
then I receive the following error:
{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "[processors] required property is missing",
"header": {
"property_name": "processors"
}
}
],
"type": "parse_exception",
"reason": "[processors] required property is missing",
"header": {
"property_name": "processors"
}
},
"status": 400
}

The _simulate endpoint works only with POST and not PUT:
POST _ingest/pipeline/removescript/_simulate
{
...
}

Related

ElasticSearch Troubleshooting Watcher : illegal_argument_exception

Watcher was working and succesfully alerting the Slack channel but now I'm having a trouble.
The only change that I've made was to update its refresh interval. When I run the following GET, it returns watcher actions's state as "awaits_successful_execution".
GET _watcher/watch/my_watcher
{
"found": true,
"_id": "etl_incr_morp_to_hermes",
"_status": {
"version": 432497,
"state": {
"active": true,
"timestamp": "2017-03-24T07:14:41.301Z"
},
"actions": {
"notify-slack": {
"ack": {
"timestamp": "2017-03-24T07:14:41.301Z",
"state": "awaits_successful_execution"
}
}
}
}
...
I've checked Elastic's documentation. When I try to get more info about watcher by calling the following API, I get this result:
GET _watcher
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "No endpoint or operation is available at [_watcher]"
}
],
"type": "illegal_argument_exception",
"reason": "No endpoint or operation is available at [_watcher]"
},
"status": 400
}
How can I troubleshot watcher? Is there any logs that I can check?
I found the answer!
The following request returns specified watcher's execution history.
GET .watcher-history*/_search
{
"query": {
"query_string": {
"query": "watch_id: my_watcher"
}
},
"size": 1,
"sort": [
{
"result.execution_time": { "order": "desc"}
}
]
}

Update a particular field in ES 2.4.0 document?

I have document like this
"College": "UCLA",
"University": "American",
"Branch": "MECH",
"Name": {
"first": "john",
"middle": "william",
"last": "Richards"
}
I have to update the last field in Name group
I tried with the following but it is showing error
POST alma/matter/1/_update
{
"doc": { "Name.last": "junior" }
}
Error:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Field name [Name.last] cannot contain '.'"
}
],
"type": "mapper_parsing_exception",
"reason": "Field name [Name.last] cannot contain '.'"
},
"status": 400
}
You're not allowed to reference fields with dots in them. You can do it like this instead:
POST alma/matter/1/_update
{
"doc": { "Name": {"last": "junior" }}
}

Getting error in Elasticsearch while creating index using postman

I have installed Elasticsearch 5.1 in ubuntu 14.04. I have performed some operations in Elasticsearch like create index, delete index etc. Then I have installed Kibana 5.1. Now I want to create new index in elasticsearch using postman (localhost:9200/my_index with PUT). But I'm getting this error.
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.country] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
}
],
"type": "illegal_argument_exception",
"reason": "unknown setting [index.country] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
},
"status": 400
}
I remember that I have used country as index or type. But then I have purged elasticsearch and kibana (also deleted directories related to those). Reinstalled both. But still getting this error. If anyone knows the solution, it will be appreciated.
Here is output of some query which may you need to solve issue.
GET localhost:9200/_mapping
{ ".kibana": {
"mappings": {
"server": {
"properties": {
"uuid": {
"type": "keyword"
}
}
},
"config": {
"properties": {
"buildNum": {
"type": "keyword"
}
}
}
} } }
(GET) localhost:9200/_cat/indices?v
[ {
"health": "yellow",
"status": "open",
"index": ".kibana",
"uuid": "O_ORG0ONQNCEe8JU_C0SKQ",
"pri": "1",
"rep": "1",
"docs.count": "1",
"docs.deleted": "0",
"store.size": "3.1kb",
"pri.store.size": "3.1kb" } ]
(GET) localhost:9200/country
{ "error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": "country",
"index_uuid": "na",
"index": "country"
}
],
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": "country",
"index_uuid": "na",
"index": "country" }, "status": 404 }
You can simply have a PUT request as such:
http://localhost:9200/indexname <--- give your index name
And then within your request body you could give the mappings:
{
"mappings": {
"message_logs": {
"properties": {
"anyfield": { <-- give your field
"type": "text" <-- and the type
}
}
}
}
}
This SO might help you if you're willing to create the index using CURL.
The above is just a sample. You could reproduce it.

ES giving error when sorting by distance

I'm trying to sort search results by distance. However, when i try i get the following error:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "sort option [location] not supported"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "roeselaredev",
"node": "2UYlfd7sTd6qlJWgdK2wzQ",
"reason": {
"type": "illegal_argument_exception",
"reason": "sort option [location] not supported"
}
}
]
},
"status": 400
}
The query i sent looks like this:
GET _search
{
"query": {
"match_all": []
},
"sort": [
{
"geo_distance": {
"location": {
"lat": 50.9436034,
"long": 3.1242917
},
"order":"asc",
"unit":"km",
"distance_type":"plane"
}
},
{
"_score": {
"order":"desc"
}
}
]
}
As near as i can tell i followed the instructions in the documentation to the letter. I'm not getting a malformed query result. I'm just getting a not supported result for the sort by distance option. Any ideas as to what i'm doing wrong?
The query dsl is invalid the OP is almost-correct :) but missing an under-score.
While sorting by distance it is _geo_distance and not geo_distance.
Example:
GET _search
{
"query": {
"match_all": []
},
"sort": [
{
"_geo_distance": {
"location": {
"lat": 50.9436034,
"long": 3.1242917
},
"order":"asc",
"unit":"km",
"distance_type":"plane"
}
},
{
"_score": {
"order":"desc"
}
}
]
}

Error in executing groovy script in elasticsearch

below is my query, I want to change score calculation using function_score feature:
{
"size": 1,
"query":{
"function_score": {
"query": {
"bool": {
"must": [
{
"match": {
"messageText": "car"
}
}
]
}
},
"script_score" : {
"script" : "doc['time_views'].values[doc['time_views'].values.length-1]"
}
,
"boost_mode": "replace"
}
},
"from": 0
}
but I got this error response
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "failed to run inline script [doc['time_views'].values[doc['time_views'].values.length-1]] using lang [groovy]"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "datacollection",
"node": "TWeZV3R6Rq-WYQ2YIHjILQ",
"reason": {
"type": "script_exception",
"reason": "failed to run inline script [doc['time_views'].values[doc['time_views'].values.length-1]] using lang [groovy]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [time_views] in mapping with types [message]"
}
}
}
]
},
"status": 500
}
some solutions says using quotation in "doc['time_views']" causes the problem when query has been send from command prompt tools. I don't know why!
I don't use any command prompt tools. I create the query in java code directly
EDIT
this is my index mapping:
"mappings": {
"message": {
"properties": {
"text": {
"type": "string"
},
"time_views": {
"type": "nested",
"properties": {
"backupTimestamp": {
"type": "long"
},
"views": {
"type": "integer"
}
}
}
}
}
}
}
I want to use "views" of last item of "time_views". so I try below scripts too, but each of them throw different error:
"doc['time_views.views'].values[doc['time_views.views'].values.length-1]"
error: java.util.ArrayList cannot be cast to java.lang.Number
"doc['time_views.views'].values[doc['time_views.views'].values.size()-1]"
error: failed to run inline script [doc['time_views.views'].values[doc['time_views.views'].values.size()-1]] using lang [groovy]
"doc['time_views'].values[doc['time_views'].values.size()-1].views"
error: failed to run inline script [doc['time_views'].values[doc['time_views'].values.size()-1].views] using lang [groovy]"
I'm really new in elasticsearch and groovy language. I didn't care about that "time_views" is nested Object, also I don't know syntax of groovy exactly, after some affort I found my mistakes and the solution:
{
"size": 1,
"query":{
"function_score": {
"query": {
"bool": {
"must": [
{
"match": {
"messageText": "car"
}
}
]
}
},
"script_score" : {
"script" : "doc['time_views.views'].values.get(doc['time_views.views'].values.size()-1)"
}
,
"boost_mode": "replace"
}
},
"from": 0
}
It's work as I expected

Resources