<commit_before>Elasticsearch-SQL
=================

Query elasticsearch using familiar SQL syntax.
You can also use ES functions in SQL.



## Web frontend overview

![Web frontend overview](https://cloud.githubusercontent.com/assets/9518816/5555009/ebe4b53c-8c93-11e4-88ad-96d805cc698f.png)


## SETUP

Install as plugin:

###Elasticsearch 1.4.X
````

./bin/plugin -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.3/elasticsearch-sql-1.3.zip --install sql

````
## Basic Usuage

* Visit The elasticsearch-sql web front end:
````
http://localhost:9200/_plugin/sql/
````


* Simple query
````
http://localhost:9200/_sql?sql=select * from indexName limit 10
````

* Explain SQL to elasticsearch query DSL
````
http://localhost:9200/_sql/_explain?sql=select * from indexName limit 10
```` 



## SQL Usuage

* Query

        SELECT * FROM bank WHERE age >30 AND gender = 'm'

* Aggregation

        select COUNT(*),SUM(age),MIN(age) as m, MAX(age),AVG(age)
        FROM bank GROUP BY gender ORDER BY SUM(age), m DESC

* Delete

        DELETE * FROM bank WHERE age >30 AND gender = 'm'


> ###Beyond sql

* Search

        SELECT address FROM bank WHERE address = matchQuery('880 Holmes Lane') ORDER BY _score DESC LIMIT 3
        

* Group by aggregation

	+ range age group 20-25,25-30,30-35,35-40

			SELECT COUNT(age) FROM bank GROUP BY range(age, 20,25,30,35,40)

	+ range date group by day

			SELECT online FROM online GROUP BY date_histogram(field='insert_time','interval'='1d')
<commit_msg>fix README<commit_after>Elasticsearch-SQL
=================

Query elasticsearch using familiar SQL syntax.
You can also use ES functions in SQL.



## Web frontend overview

![Web frontend overview](https://cloud.githubusercontent.com/assets/9518816/5555009/ebe4b53c-8c93-11e4-88ad-96d805cc698f.png)


## SETUP

Install as plugin:

###Elasticsearch 1.4.X
````

./bin/plugin -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.3/elasticsearch-sql-1.3.zip --install sql

````
## Basic Usuage

* Visit The elasticsearch-sql web front end:
````
http://localhost:9200/_plugin/sql/
````


* Simple query
````
http://localhost:9200/_sql?sql=select * from indexName limit 10
````

* Explain SQL to elasticsearch query DSL
````
http://localhost:9200/_sql/_explain?sql=select * from indexName limit 10
```` 



## SQL Usuage

* Query

        SELECT * FROM bank WHERE age >30 AND gender = 'm'

* Aggregation

        select COUNT(*),SUM(age),MIN(age) as m, MAX(age),AVG(age)
        FROM bank GROUP BY gender ORDER BY SUM(age), m DESC

* Delete

        DELETE FROM bank WHERE age >30 AND gender = 'm'


> ###Beyond sql

* Search

        SELECT address FROM bank WHERE address = matchQuery('880 Holmes Lane') ORDER BY _score DESC LIMIT 3
        

* Group by aggregation

	+ range age group 20-25,25-30,30-35,35-40

			SELECT COUNT(age) FROM bank GROUP BY range(age, 20,25,30,35,40)

	+ range date group by day

			SELECT online FROM online GROUP BY date_histogram(field='insert_time','interval'='1d')

{'fraction_non_alphanumeric': 0.13842087875784606, 'fraction_numerical': 0.05946481665014866, 'mean_word_length': 3.7238689547581902, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3328599', 'n_tokens_mistral': 1162, 'n_tokens_neox': 975, 'n_words': 285}