Questions tagged [elasticsearch-sql]

Elasticsearch-SQL is a SQL-like syntax for Elasticsearch introduced in version 6.3 of the Elastic Stack via the x-pack plugin.

Elasticsearch-SQL was introduced in x-pack 6.3. It provides a SQL-like syntax for developers familiar with SQL concepts and is ultimately translated to a Elasticsearch DSL query. The syntax is targeted at new users and data consumers who do not want the complexity or need the features of the full DSL.

Resources

Elasticsearch Demo Site

An Introduction to Elasticsearch SQL with Practical Examples - Part 1

An Introduction to Elasticsearch SQL with Practical Examples - Part 2

Example Query

POST /_xpack/sql?format=txt
{
  "query": "SELECT FlightNum FROM flights LIMIT 10"
}

Translates to this traditional DSL query:

{
  "size": 10,
  "_source": {
    "includes": [
      "FlightNum"
    ],
    "excludes": []
  },
  "sort": [
    {
      "_doc": {
        "order": "asc"
      }
    }
  ]
}

And returns the following response:

FlightNum   
---------------
X98CCZO        
9HY9SWR        
XEJ78I2        
P0WMFH7        
UFK2WIZ        
EAYQW69        
1IRBW25        
JQ2XXQ5        
7TTZM4I        
EVARI8I        
21 questions
4
votes
2 answers

Elasticsearch SQL-Query not possible

I got a ElasticSearch Instance running locally which works fine. Now I want to query an index using SQL. I tried it with the NodeJS-Client (v7) and normally via the REST-Api. Rest call: POST http://localhost:9200/_sql { "body": { "query":…
m_____0
  • 375
  • 5
  • 18
2
votes
1 answer

Use SQL Access in Elasticsearch python client

I am trying to use the python client for elastic search to query an index using SQL access for elastic search. I want to query an index using sql syntax. How do i specify to elasticsearch that it has to read SQLsyntax? def searchText(text): t1…
2
votes
3 answers

Return all rows in a Elasticsearch SQL query

I have a simple SQL query in Elasticsearch which I know returns less than 100 rows of results. How can I get all these results at once (i.e., without using scroll)? I tried the limit n clause but it works when n is less than or equal to 10 but…
Benjamin Du
  • 1,391
  • 1
  • 17
  • 25
1
vote
0 answers

How to map the result of elasticsearch SQL API request to a java POJO?

I am trying to send SQL queries to elasticsearch server using the SQL API ( I am using the free version so I can't use the JDBC driver they provide) and I was wondering how I can map the result of the query since it comes back like this: { …
1
vote
0 answers

How to do an Elasticsearch SQL query for geo_point data

I have an ES index which contains a mapping of type geo_point. I want to use the Elasticsearch SQL API to do a bounding box query. I know how to do this using ES DSL as per the ES docs. How would I express this in SQL query form? In sort what SQL…
1
vote
0 answers

Filter not equal is it supported in Elasticsearch SQL API

According to Elasticsearch doc it doesn't support arrays in SQL api. I ended up using filter but it's doesn't work for my case. include product ids works fine "body": { "query" :"SELECT email FROM orders WHERE shop='domain' GROUP BY…
Khalid Skiod
  • 103
  • 3
  • 8
1
vote
1 answer

SQL aggregation query corresponding in elasticsearch

I studied elasticsearch aggregation queries but couldn't find if it supports multiple aggregate function. In an other word, I wanna know if elasticsearch can generate the equivalent of this Sql aggregation query: SELECT account_no,…
1
vote
1 answer

Elasticsearch SQL query in Canvas : it doesn't work like SQL?

I begin to work with the Canvas section in Kibana - and to retrieve data, it uses Elasticsearch SQL. What I try to do is to retrieve the count of several values ; and I need to group certain values together - the ones that start with the same…
Lobotomeh
  • 65
  • 1
  • 1
  • 5
0
votes
0 answers

How to search opensearch sorted by distance using sql plugin?

We use SQL plugin for querying OpenSearch in order to simplify the queries (so many ANDs and ORs). We are able to limit the results based on the given radius (which was quite hard to figure out), the SQL query looks like this: SELECT name FROM…
Ikar Pohorský
  • 4,617
  • 6
  • 39
  • 56
0
votes
1 answer

Handle response from SQL query in Elastic.Clients.Elasticsearch 8.1.0 for .NET

I have an Elasticsearch cluster, which e.g. contains an index called persons. I want to query the documents of the index using the SQL API of Elasticsearch. When using the REST API of Elasticsearch via Kibana everything works fine: POST…
0
votes
1 answer

ES SQL result doesn't use correct date mapping

I'm experimenting with the SQL options from Elasticsearch and I noticed that a timestamp field that I mapped as "strict_date_optional_time_nanos||epoch_millis" doesn't show up as it is indexed. This is what the timestamp column looks like when I do…
Pompompurin
  • 165
  • 3
  • 14
0
votes
1 answer

elasticsearch SQL query in python

elasticsearch == 7.16.1 Trying to run a very simple query just to try out the SQL implementation w/python. es.sql.query(body={'query':'select * from index_name-* limit 100'}) Getting this error: RequestError: RequestError(400, 'parsing_exception',…
chowpay
  • 1,515
  • 6
  • 22
  • 44
0
votes
0 answers

Cannot get cardinality count in elasticsearch

I am not able to get cardinality of a field from an elasticsearch index. The mapping is as follows: And the query which I am trying to fire is as follows: --header 'Content-Type: application/json' \ --data-raw '{ "aggs": { …
sky
  • 260
  • 3
  • 12
0
votes
1 answer

Use query result as parameter for another query in Elasticsearch DSL

I'm using Elasticsearch DSL, I'm trying to use a query result as a parameter for another query like below: { "query": { "bool": { "must_not": { "terms": { "request_id": { "query": { "match": { …
0
votes
1 answer

Elasticserach sql query with passing parameters so we prevent sql Injection

I am using elastic search 7.6.2 version. Passing parameters to a query not working in kibana. When I am trying to add params query not working in kibana dev tool if we try with params query will work fine. POST /_sql?format=txt …
1
2