CottageLabs / edges

Data query, manipulation, search and visualisation front-end library
MIT License
8 stars 7 forks source link

ES 5.1 #5

Closed dlwaticg closed 6 years ago

dlwaticg commented 7 years ago

Has anyone gotten Edges to work with Elastic Search 5.x?

I am getting parse errors on the most basic usage - see code snippet below. Error message is "request [/gmail/search] contains unrecognized parameters: [], [callback]". The input url string is :

http://localhost:9200/gmail/_search?callback=jQuery111105851623103653166_1482796045779&source=%7B%22query%22%3A%7B%22query_string%22%3A%7B%22query%22%3A%22Fariba%22%2C%22default_operator%22%3A%22OR%22%7D%7D%7D&_=1482796045780

jQuery(document).ready(function($) { d = false; function cb(data) { d = data; }

q = es.newQuery({
    filtered: true,
    /*size : 10,
    from : 0,*/
    queryString: "Steve", 
    /*sort : {field: "date", order: "asc"}, 
    fields: ["subject"] */
});

o = q.objectify();

es.doQuery({
    search_url: "http://localhost:9200/gmail/_search",
    queryobj: q.objectify(),
    datatype: "jsonp",
    success: cb
});

console.log(d)
richard-jones commented 7 years ago

There are some breaking changes between 1.x/2.x and 5.x and there's a new es layer which accounts for them:

https://github.com/CottageLabs/edges/blob/develop/src/es5x.js

All you should need to do is switch es.js for es5x.js and your code should work.

For reference, the key thing that's different is that filtering no longer works the way it used to, so a filtered query will fail.

dlwaticg commented 7 years ago

Richard, Thank you so much. I now have the basics working. I am seeing some weirdness when combining newOrTermSelectors with newFullSearchController in that the queries being sent to ES 5.1 are getting a parsing exception. I suspect something is wrong in the merge function related to new ES syntax? The example was very helpful, however I am unable to get the newDateHistogramSelector to work as a facet. I notice that the function calls edges.BasicRangeSelector ( selectors.js, line 772) - is that correct? Thanks for all the help, I think this library is very well put together and extremely powerful, I hope to see it mature a bit and include more docs. I will post what I have learned as soon as I get something that is presentable and I am sure I understand what I am doing. Thanks again. /david

richard-jones commented 7 years ago

Hi David,

We haven't done very deep testing on the 5.x version of ES yet, so it's entirely possible that there are further bits in es5x.js that will need to change, yes. If you are able to share your usage of the code, I could see if there's anything obvious that stands out as wrong with the ORTermsSelector and the FullSearchController.

Looking at the DateHistogramSelector, it looks like it's just a stub at this stage (we have lots of bits where further dev is needed!), which probably explains why it doesn't work. The constructor just seems to create a BasicRangeSelector, as you say :)

I'm glad you're finding it useful! We're just getting to the stage now where the documentation and the overall build/deployment process is becoming the bottleneck, and we have some work on that front planned in the coming months. We'd always be happy to accept contributions and suggestions too, so would be very glad to hear about your experiences with it.

Cheers, Richard

dlwaticg commented 7 years ago

Richard, Thanks for the prompt reply and willingness to help. Attached is my sample app. The weird behavior is when combining facets (regardless of type) with the search. The resulting query and error message is below:

GENERATED example.zip

QUERY GET gmail/_search { "query":{ "query_string":{ "query":"della", "default_operator":"OR" }, "bool":{ "must":[{ "terms":{ "from":["david.waldrop@gmail.com"] } }] } }, "size":0, "aggs":{ "to":{ "terms":{ "field":"to", "size":100, "order":{ "_count":"desc" } } } } }

RESULT { "error": { "root_cause": [ { "type": "parsing_exception", "reason": "[query_string] malformed query, expected [END_OBJECT] but found [FIELD_NAME]", "line": 7, "col": 5 } ], "type": "parsing_exception", "reason": "[query_string] malformed query, expected [END_OBJECT] but found [FIELD_NAME]", "line": 7, "col": 5 }, "status": 400 }

richard-jones commented 7 years ago

Ok, I see what's going on, thanks.

The code which generates the query is adding the "query_string" filter and the "bool" filter next to each other, which is syntactically incorrect. It's a hangover from the filtered queries prior to es 5.x, and how the es.js module handled them, which I overlooked when doing the port.

I've just committed some code (to the develop branch) which puts them all together in the bool query, and parses them out correctly when reading queries in.

https://github.com/CottageLabs/edges/commit/2da4e9a4ab57216031e98ab4908902dea86138e2

I was able to reproduce a bug similar to yours (though not exactly the same) on a test system of my own, and these changes fixed it, so hopefully they will do the same for you!