elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

search_phase_execution_exception errors

Open mattupstate opened this issue 11 years ago • 5 comments

I'm constantly getting search_phase_execution_exception errors and can't figure out why, even when I add the appropriate CLI flags to get more output. This is running against Elasticsearch v2.1.0.

$ elastalert --config /etc/elastalert/config.yaml --debug --es_debug --verbose --es_debug_trace /etc/elastalert/errors.log
ERROR:root:Error running query: TransportError(500, u'search_phase_execution_exception')
Skipping writing to ES: {'message': "Error running query: TransportError(500, u'search_phase_execution_exception')", 'traceback': ['Traceback (most recent call last):', '  File "/usr/local/lib/python2.7/site-packages/elastalert/elastalert.py", line 258, in get_hits', '    res = self.current_es.search(index=index, size=self.max_query_size, body=query, ignore_unavailable=True, **extra_args)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped', '    return func(*args, params=params, **kwargs)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 530, in search', "    doc_type, '_search'), params=params, body=body)", '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 307, in perform_request', '    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 93, in perform_request', '    self._raise_error(response.status, raw_data)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 105, in _raise_error', '    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)', "TransportError: TransportError(500, u'search_phase_execution_exception')"], 'data': {'rule': 'CPU spike'}}
INFO:elastalert:Skipping writing to ES: {'message': "Error running query: TransportError(500, u'search_phase_execution_exception')", 'traceback': ['Traceback (most recent call last):', '  File "/usr/local/lib/python2.7/site-packages/elastalert/elastalert.py", line 258, in get_hits', '    res = self.current_es.search(index=index, size=self.max_query_size, body=query, ignore_unavailable=True, **extra_args)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped', '    return func(*args, params=params, **kwargs)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 530, in search', "    doc_type, '_search'), params=params, body=body)", '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 307, in perform_request', '    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 93, in perform_request', '    self._raise_error(response.status, raw_data)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 105, in _raise_error', '    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)', "TransportError: TransportError(500, u'search_phase_execution_exception')"], 'data': {'rule': 'CPU spike'}}
Ran CPU spike from 12-2 22:31 UTC to 12-2 23:16 UTC: 0 query hits, 0 matches, 0 alerts sent
INFO:elastalert:Ran CPU spike from 12-2 22:31 UTC to 12-2 23:16 UTC: 0 query hits, 0 matches, 0 alerts sent
Sleeping for 299 seconds
curl -XGET 'http://localhost:9200/elastalert/elastalert/_search?pretty&size=1000' -d '{
  "filter": {
    "range": {
      "alert_time": {
        "from": "2015-11-30T23:18:39.844621Z",
        "to": "2015-12-02T23:18:39.844645Z"
      }
    }
  },
  "query": {
    "query_string": {
      "query": "alert_sent:false"
    }
  }
}'
curl -XGET 'http://localhost:9200/elastalert/elastalert_status/_search?pretty&_source_include=endtime%2Crule_name&size=1' -d '{
  "filter": {
    "term": {
      "rule_name": "CPU spike"
    }
  },
  "sort": {
    "@timestamp": {
      "order": "desc"
    }
  }
}'
$ elastalert-test-rule  /etc/elastalert/rules/cpu_spike.yaml
ERROR:root:Error running query: TransportError(500, u'search_phase_execution_exception')
Successfully loaded CPU spike

Got 110 hits from the last 1 day

Available terms in first hit:
    count
    load.load1
    load.load15
    load.load5
    tags
    beat.hostname
    beat.name
    @timestamp
    mem.actual_free
    mem.used
    mem.used_p
    mem.free
    mem.actual_used_p
    mem.actual_used
    mem.total
    swap.actual_free
    swap.used
    swap.used_p
    swap.free
    swap.actual_used_p
    swap.actual_used
    swap.total
    type
    cpu.system_p
    cpu.softirq
    cpu.iowait
    cpu.system
    cpu.user_p
    cpu.user
    cpu.irq
    cpu.steal
    cpu.idle
    cpu.nice


Would have written the following documents to elastalert_status:

elastalert_error - {'message': "Error running query: TransportError(500, u'search_phase_execution_exception')", 'traceback': ['Traceback (most recent call last):', '  File "/usr/local/lib/python2.7/site-packages/elastalert/elastalert.py", line 258, in get_hits', '    res = self.current_es.search(index=index, size=self.max_query_size, body=query, ignore_unavailable=True, **extra_args)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped', '    return func(*args, params=params, **kwargs)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 530, in search', "    doc_type, '_search'), params=params, body=body)", '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 307, in perform_request', '    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 93, in perform_request', '    self._raise_error(response.status, raw_data)', '  File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 105, in _raise_error', '    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)', "TransportError: TransportError(500, u'search_phase_execution_exception')"], 'data': {'rule': 'CPU spike'}}
# cpu_spike.yaml
es_host: <host>
es_port: 9200
name: CPU spike
type: spike
index: topbeat-*
threshold: 10
timeframe:
  hours: 1
spike_height: 3
spike_type: "up"
filter:
  - query:
      query_string:
        query: "type:system AND cpu.user_p:[0.5 TO 1]"

# (Required)
# The alert is use when a match is found
alert:
 - "email"

# (required, email specific)
# a list of email addresses to send alerts to
email:
  - "<email>"

mattupstate avatar Dec 03 '15 15:12 mattupstate

we had the same problem when we upgraded to es 2.1.0 , try setting max_query_size: 10000 in config.yaml

ref: https://github.com/elastic/elasticsearch/pull/13188

silvaireboivert avatar Dec 07 '15 20:12 silvaireboivert

Thanks for the info @silvaireboivert. I think that's good enough reason to drop the default down to 10,000.

Qmando avatar Dec 07 '15 21:12 Qmando

@silvaireboivert thanks for the tip, that did get rid of the errors.

mattupstate avatar Dec 08 '15 14:12 mattupstate

@silvaireboivert also helped me with the same error

One thing to note, elastalert-test-rule does not pick up that setting from the config.yaml files so it still will not work.

tfgm-bud avatar Dec 09 '15 22:12 tfgm-bud

I was trying to query for an int and string field inside the same query. And that was what caused this error.

ittimtadej avatar May 14 '18 07:05 ittimtadej