November Happy Hour will be moved to Thursday December 5th.

Querying using Javascript

Vote:
 

Hi,

We're querying the EpiServer index using javascript and the query DSL. What version of the API do you support on the EpiServer endpoint?

Quite a few examples in the, admitedly patchy, documentation don't work with the EpiServer index and I'm struggling to formulate the queries correctly.

For example, I'm trying to do a more like this on document IDs:

{
	"query": {
		"filtered": {
			"query": {
				"more_like_this": {
					
                "fields" : ["title", "description"],
                "like" : [
                {
                    "_index" : "hpss",
                    "_id" : "1"
                }]
                    
                    
                    
                    
				}
			},
			"filter": {
				"term": {
					"___types": "com.okana.Document"
				}
			}
		}
	}
}

With a response like this:

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[ctHumoCTTFCBdrUjP0KccQ][gordon_hpss][0]: SearchParseException[[gordon_hpss][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"more_like_this":{"fields":["title","description"],"like":[{"_index":"hpss","_id":"1"}]}},"filter":{"term":{"___types":"com.okana.Document"}}}}}]]]; nested: QueryParsingException[[gordon_hpss] [mlt] query does not support [like]]; }{[IttFE-HTTry6zDCpm-vLDw][gordon_hpss][1]: RemoteTransportException[[euw1bfinddev02esd02][inet[/10.54.4.202:9300]][search/phase/query]]; nested: SearchParseException[[gordon_hpss][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"more_like_this":{"fields":["title","description"],"like":[{"_index":"hpss","_id":"1"}]}},"filter":{"term":{"___types":"com.okana.Document"}}}}}]]]; nested: QueryParsingException[[gordon_hpss] [mlt] query does not support [like]]; }]"
"status": 400
}
#145905
Mar 15, 2016 10:42
Vote:
 

This API should work: https://www.elastic.co/guide/en/elasticsearch/reference/0.90/search-more-like-this.html

However, please, consider to use Episerver Find .NET API instead: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/9/DotNET-Client-API/Searching/More-LikeRelated/. Even though we try to keep backward compatibility, direct requests to the index might have breaking changes. Using .NET API is more reliable in terms of possible breaking changes in the future updates.

#145910
Mar 15, 2016 13:50
Vote:
 

Hi, 

Thanks for the response. So we can only use the 0.90 version of the API? The C# API is no good to us as we require client-side access for speed. 

Thanks

Gordon

#145915
Mar 15, 2016 15:33
Vote:
 

Yes, for now, it is 0.90, but it will change in the future. Regarding the speed considerations, there might be not so much gain from using the client-side access. Have you done any performance tests to compare the difference?

#145920
Mar 15, 2016 16:06
Vote:
 

Hi Sergil,

It's more to do with avoiding page postbacks rather than the pure speed of the calls.

Thanks

Gordon

#145921
Mar 15, 2016 16:10
Vote:
 

OK, then you might consider to introduce an endpoint on the web server, that recieves request from JavaScript and calls Episerver Find .NET API. In that case you will safeguard your code from potential breaking changes in elasticsearch API. 

#145922
Mar 15, 2016 16:47
Vote:
 

Hi,

Further to your above comment; are there any updates planned in the next few weeks? We've built a demo and can't risk the interface changing.

I'm suprised that you recommend not using the javascript API, you talk about using it here:

http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/11/searching-with-javascript/Searching-with-Javascript/

Thanks

Gordon

#145923
Mar 15, 2016 16:51
Vote:
 

I would also expose my own endpoint on webbserver and use the NET api. Find has too much fine extension methods etc that I would hate to try to mimic and figure out the correct js calls... 

When elastic search is upgraded it will also be a world of pain...

#145924
Mar 15, 2016 16:58
Vote:
 

Thanks

It might be useful for other developers to point this out on the javascript page to save going down a dead-end.

Cheers

Gordon

#145928
Mar 15, 2016 17:07
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.