Skip to content

Commit 8fc9fc3

Browse files
committed
moved @abibell tip to a specialized section in the docs
1 parent b89328c commit 8fc9fc3

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
template: layout.jade
3+
title: Tips & Tricks
4+
menusection:
5+
menuitem: tips-tricks
6+
---
7+
8+
# Tips & Tricks
9+
10+
This page lists some general tips and tricks provided by the community
11+
12+
## Posting Elasticsearch queries from javascript
13+
14+
Consider a scenario where you are using client side libraries like [elasticjs](https://github.com/fullscale/elastic.js)
15+
but want security to be provided by server side business logic. Consider this example using `WebAPI`
16+
17+
**NOTE** make sure dynamic scripting is turned off if you decide to open the full query DSL to the client!
18+
19+
```cs
20+
[RoutePrefix("api/Search")]
21+
public class SearchController : ApiController
22+
{
23+
[ActionName("_search")]
24+
public IHttpActionResult Post([FromBody]SearchDescriptor<dynamic> query)
25+
{;
26+
var client = new ElasticClient();
27+
28+
//Your server side security goes here
29+
30+
var result = client.Search(q => query);
31+
return Ok(result);
32+
}
33+
}
34+
```
35+
The fragments `[RoutePrefix("api/Search")]` and `[ActionName("_search")]` will let you change your elastic search Url
36+
from `http://localhost:9200/_search` to `http://yourwebsite/api/Search/_search` and let things work as normal.
37+
The fragment `[FromBody]SearchDescriptor<dynamic> query` will convert the JSON query into NEST SearchDescriptor.
38+
The fragment `client.Search(q => query)` will execute the query.

new_docs/templates/side_menu.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ aside#menu
2424
li: a(class=(page.metadata.menuitem == 'index-type-inference')? "selected" : "", href="/nest/index-type-inference.html") Type/Index Inference
2525
li: a(class=(page.metadata.menuitem == 'handling-responses')? "selected" : "", href="/nest/handling-responses.html") Handling responses
2626
li: a(class=(page.metadata.menuitem == 'writing-queries')? "selected" : "", href="/nest/writing-queries.html") Writing queries
27+
li: a(class=(page.metadata.menuitem == 'tips-tricks')? "selected" : "", href="/nest/tips-tricks.html") Tips & Tricks
2728
- if (page.metadata.menusection == 'core' )
2829
h4
2930
i.fa.fa-chevron-down

0 commit comments

Comments
 (0)