NLPchina / elasticsearch-sql

Use SQL to query Elasticsearch
Apache License 2.0
7k stars 1.54k forks source link

Generating a DSL statement is not working well #433

Open TarryHoo opened 7 years ago

TarryHoo commented 7 years ago

Hey man, I recently found one thing when I was in use,SQL to the place where the DSL statement is nested. E.g: select id,orgcode,carnum,truckid,gpsno,drivername,intime,outtime,stoptime,orgroot,type,marker_name fromtruck_alarm_eventWHERE deleted = 0 AND orgcode LIKE '20008D%' AND intime between ${start_time} AND ${end_time} AND ((marker_orgcode LIKE '20008D%' AND marker_privacy = 0) or (marker_orgcode LIKE '20008D%' AND marker_privacy = 1)) LIMIT 0,100; SQL parsing DSl statement to get this result {"from":0,"size":100,"query":{"bool":{"filter":{"bool":{"must":{"bool":{"must":[{"match":{"deleted":{"query":0,"type":"phrase"}}},{"wildcard":{"orgcode":"20008D*"}},{"range":{"intime":{"from":1487053746610,"to":null,"include_lower":true,"include_upper":true}}},{"range":{"intime":{"from":null,"to":1489472946610,"include_lower":true,"include_upper":true}}},{"bool":{"should":[{"bool":{"must":[{"wildcard":{"marker_orgcode":"20008D*"}},{"match":{"marker_privacy":{"query":0,"type":"phrase"}}}]}},{"bool":{"must":[{"wildcard":{"marker_orgcode":"20008D*"}},{"match":{"marker_privacy":{"query":1,"type":"phrase"}}}]}}]}}]}}}}}},"_source":{"includes":["id","orgcode","carnum","truckid","gpsno","drivername","intime","outtime","stoptime","orgroot","type","marker_name"],"excludes":[]}} However, this DSL structure makes me uncomfortable.I think the following is good on this. { "from": 0, "size": 100, "query": { "filtered": { "filter": { "bool": { "must": [ { "match": { "deleted": { "query": 0, "type": "phrase" } } }, { "wildcard": { "orgcode": "20008D*" } }, { "range": { "intime": { "from": 1487053746610, "to": 1489472946610, "include_lower": true, "include_upper": true } } }, { "wildcard": { "marker_orgcode": "20008D*" } }, { "bool": { "should": [ { "bool": { "must": [ { "match": { "marker_privacy": { "query": 0, "type": "phrase" } } } ] } }, { "bool": { "must": [ { "match": { "marker_privacy": { "query": 1, "type": "phrase" } } } ] } } ] } } ] } } } }, "_source": { "includes": [ "id", "orgcode", "carnum", "truckid", "gpsno", "drivername", "intime", "outtime", "stoptime", "orgroot", "type", "marker_name" ], "excludes": [] } }

What do you think of? @all

TarryHoo commented 7 years ago

@eliranmoyal @ansjsun What do you think of?