NLPchina / elasticsearch-sql

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

Unsupported method: reverse_nested #168

Closed Selvinaz1984 closed 8 years ago

Selvinaz1984 commented 8 years ago

Hello,

I am using Elasticsearch-SQL plugin 1.4.8 and need to use the reverse_nested method for my query: SELECT * FROM eventindextest1/EventBean where nested(attributes.paramKey)='BLOCK' and reverse_nested(attributes.value)='880'

I want to query all events where blockId (BLOCK) =880, but I receive following error: {"error":"SqlParseException[unsupported method: reverse_nested]","status":500}!

Is this method is not supported in 1.4.8??

My mapping for the attributes is like: "EventBean" : { "properties" : { "attributes" : { "type" : "nested", "properties" : { "derivedData" : { "type" : "boolean" }, "paramKey" : { "type" : "string", "index" : "not_analyzed", "doc_values" : true }, "value" : { "type" : "string", "index" : "not_analyzed", "doc_values" : true } } Example data: "attributes" : [ { "paramKey" : "BLOCK", "value" : "880" }, { "paramKey" : "COURSE", "value" : "198" }, ...

Is it possible to declare a sql query which queries all events with BLOCK=880 and COURSE=198??

eliranmoyal commented 8 years ago

Reverse nested is only used for aggregations...... There is no need to use it here Read about nested here https://github.com/NLPchina/elasticsearch-sql/wiki/NestedTypes-queries

For your usage if you want docs with attributes that contains an attribute which have key 'block' and value 880 just do Select * from myindex where nested('attributes', attributes.paramkey='BLOCK' and value=880)

Selvinaz1984 commented 8 years ago

Will I also receive results with for example LINE=880? I just want events with BLOCK=880, no LINE=880.

And what is the query notation if I want to combine tweo attribute queries, for example BLOCK=880 and LINE=7?

eliranmoyal commented 8 years ago

for BLOCK=880 and LINE!=800

SELECT * FROM x
where nested('attributes',attributes.paramkey='BLOCK' and attributes.value=880)
and nested('attributes',attributes.paramkey='LINE' and attributes.value<>880)

for BLOCK=880 and LINE=7

SELECT * FROM x
where nested('attributes',attributes.paramkey='BLOCK' and attributes.value=880)
and nested('attributes',attributes.paramkey='LINE' and attributes.value=7)
Selvinaz1984 commented 8 years ago

I have tested already this query. SELECT * FROM eventindextest1/EventBean where nested('attributes',attributes.paramkey='BLOCK' and attributes.value=880) and nested('attributes',attributes.paramkey='LINE' and attributes.value=7)

but receive following error:

Error: {"error":"SqlParseException[AND is err!]","status":500}??

eliranmoyal commented 8 years ago

ok it it a known issue which i've fixed #131 i'll create a release with more features this sunday

Selvinaz1984 commented 8 years ago

Hi,

thanks veryy much :) Will it be a newer release 1.4.9 for Elasticsearch 1.X?