grafana/grafana — pull request #785 by eddawley (2014-09-09 19:35:47+00:00)
Title: Better support for elasticsearch search grammar + async search request fix

Two issues are being addressed in this pull request: async search results trampling each other and partial searches not adhering to elasticsearch grammar.

## async search results
Since the partial searches can return out of order, the displayed search results will often be for an older partial search. This is especially noticeable as your number of dashboards increases and elasticsearch slows down for the more general initial partial searches.

The fix is just to keep a global counter that we compare with the local one to see if we are on the latest search query. If not, throw the results away. This fix is datasource agnostic.

## elasticsearch grammar
Previously, the code would blindly add a * to the end of the querystring in order to make it partial. This pretty much breaks all the more complex features of the elasticsearch grammar and makes many searches impossible. It was also previously calling toLower() on everything and then attempting to fix one reserved word (AND) but only doing that for the first occurrence.

The proposed fix attempts to leave the search box as close to direct elasticsearch grammar as possible. As such, it no longer auto-lowercases things for you. It will also now check for basic grammar constructs before appending the *.

See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax