maggienj / ActiveData

Provide high speed filtering and aggregation over data
Mozilla Public License 2.0
0 stars 0 forks source link

For Journal Entry - Err: query malformed, no start_object after query name #20

Closed maggienj closed 7 years ago

maggienj commented 7 years ago

UnitTest: TestEdge1.test_count_rows

caused by
    ERROR: Problem with search (path=/testing_000_n/test_result/_search):
    {
        "aggs": {
            "_match": {"terms": {
                "field": "a",
                "include": ["c"],
                "size": 1
            }},
            "_missing": {"filter": {"or": [
                {"missing": {"field": "a"}},
                {"not": {"terms": {"a": ["c"]}}}
            ]}}
        },
        "size": 1
    }
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\env\elasticsearch.py", line 1107, in search
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\queries\es09\util.py", line 40, in post
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\queries\es14\aggs.py", line 337, in es_aggsop
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\queries\jx_usingES.py", line 157, in query
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\queries\jx.py", line 71, in run
    File "C:\Users\user\PycharmProjects\ActiveData\active_data\actions\jx.py", line 62, in jx_query
    File "C:\Users\user\PycharmProjects\ActiveData\active_data\__init__.py", line 54, in output

ERROR: Problem with call to http://localhost:9200/testing_000_n/test_result/_search
{"aggs": {"_match": {"terms": {"field": "a", "include": ["c"], "size": 1}}, "_missing": {"filter": {"or": [{"missing": {"field": "a"}}, {"not": {"terms": {"a": ["c"]}}}]}}}, "size": 1}
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\env\elasticsearch.py", line 782, in post

caused by
    ERROR: Bad Request: {"error":{"root_cause":[{"type":"parsing_exception","reason":"[or] **query malformed, no start_object after query name**","line":1,"col":107}],"type":"parsing_exception","reason":"[or] query malformed, no start_object after query name","line":1,"col":107},"status":400}
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\env\elasticsearch.py", line 760, in post
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\env\elasticsearch.py", line 1100, in search
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\queries\es09\util.py", line 40, in post
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\queries\es14\aggs.py", line 337, in es_aggsop
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\queries\jx_usingES.py", line 157, in query
    File "C:\Users\user\PycharmProjects\ActiveData\pyLibrary\queries\jx.py", line 71, in run
    File "C:\Users\user\PycharmProjects\ActiveData\active_data\actions\jx.py", line 62, in jx_query
    File "C:\Users\user\PycharmProjects\ActiveData\active_data\__init__.py", line 54, in output

2017-06-07 03:33:09 - Deleting index testing_000_n20170607_033300
2017-06-07 03:33:09 - GET http://localhost:9200/_aliases
2017-06-07 03:33:09 - response: {"testing_000_x20170607_032437":{"aliases":{"testing_000_x"...<snip>...sting_000_y":{}}},"testdata20170607_023216":{"aliases":{}}}
2017-06-07 03:33:09 - 
http://localhost:9200/_aliases:
    {"actions": [{"remove": {"index": "testing_000_n20170607_033300", "alias": "testing_000_n"}}]}
2017-06-07 03:33:09 - PUT http://localhost:9200/_aliases
2017-06-07 03:33:09 - response: {"acknowledged":true}
2017-06-07 03:33:09 - delete response {"acknowledged": true} 

Ran 1 test in 9.495s

FAILED (errors=1)

Process finished with exit code 1
maggienj commented 7 years ago

The or filter is replaced in favour of the bool query.

So, in the above query, "or" and "and" should be removed. 
-- Will have to try with "should" for "or" 
-- and
-- Will have to try with "must" for "and"
-- will have to change the query as a bool query.

Ref: https://github.com/yiisoft/yii2-elasticsearch/issues/41

https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-or-filter.html

maggienj commented 7 years ago

And / Or / Not have been deprecated and replaced with bool filter. https://github.com/elastic/elasticsearch/issues/8960

maggienj commented 7 years ago

This is an agg.... so i guess, conversion to "bool" is not required in this context.

maggienj commented 7 years ago

I guess, this aggregation looks like a "multi-bucket" aggregation and therefore we could use the "filters" aggregation...

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html

But, I remember that our goal is to bucket one document into ONE bucket only... (i.e.) the same document cannot be put into two buckets.... so.. one document MUST be put into ONE and ONLY one bucket. Having said that, I'm not sure, if the above referenced doc related to "filters aggregation" would satisfy that condition.

maggienj commented 7 years ago
{
        "aggs": {
            "_match": {"terms": {
                "field": "a",
                "include": ["c"],
                "size": 1
            }},
            "_missing": {"filter": {"or": [
                {"missing": {"field": "a"}},
                {"not": {"terms": {"a": ["c"]}}}
            ]}}
        },
        "size": 1
    }

There are two buckets in this aggregation. The first bucket by name "_match" is using "terms" clause. and the second bucket by name "_missing" is using "filter" clause.

So, it looks like that the first bucket is a "terms aggregation" and the second bucket is a "filter aggregation".

klahnakoski commented 7 years ago

Since this issue is covering TestEdge1.test_count_rows, and you already have a bug for that, I suggest closing it. Or, you might want to rename this issue with a prefix "For journal entry - " like you have done the others.

maggienj commented 7 years ago

renamed.