apility/elasticsearch-sql-parser

Library for parsing SQL into the Elasticsearch DSL

v1.0.7 2022-07-26 12:56 UTC

This package is auto-updated.

Last update: 2024-10-26 18:06:38 UTC


README

Installation

composer require apility/elasticsearch-sql-parser

Usage

<?php

use Apility\ElasticSearch\SQLParser;

$query = "SELECT * FROM articles WHERE published = 1 ORDER BY updated LIMIT 10";
$parsed = SQLParser::parse($query); // ElasticSearch Query DSL

Example output

{
    "index": "articles",
    "from": 0,
    "size": 10,
    "query": {
        "bool": {
            "filter": [
                {
                    "bool": {
                        "must": [
                            {
                                "match_phrase": {
                                    "published": {
                                        "query": "1"
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "sort": [
        {
            "updated": {
                "order": "ASC"
            }
        }
    ],
    "_source": {
        "include": [
            "id",
            "name",
            "author"
        ]
    }
}