Skip to content

Commit b89328c

Browse files
committed
Merge branch 'patch-1' of github.com:abibell/elasticsearch-net into abibell-patch-1
2 parents fc374f7 + 9b70d71 commit b89328c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

new_docs/contents/nest/quick-start.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,23 @@ Again the same inferring rules apply as this will hit `/my-application/person/_s
125125
.AllTypes()
126126
);
127127

128+
## Custom server side security while searching
129+
130+
Consider a scenario where you are using client side libraries like [elasticjs](https://github.com/fullscale/elastic.js) to construct to create User interfaces but want security to be provided by server side business logic, you can take this approach. You can route your queries through server side code.
131+
```cs
132+
[RoutePrefix("api/Search")]
133+
public class SearchController : ApiController
134+
{
135+
[ActionName("_search")]
136+
public IHttpActionResult Post([FromBody]SearchDescriptor<dynamic> query)
137+
{
138+
var setting = new ConnectionSettings(new Uri(ConfigurationManager.AppSettings["SearchServerUri"])).SetDefaultIndex("informit");
139+
var client = new ElasticClient(setting);
140+
141+
//Your server side security goes here
142+
var result = client.Search(q => query);
143+
return Ok(result);
144+
}
145+
}
146+
```
147+
The fragments `[RoutePrefix("api/Search")]` and `[ActionName("_search")]` will let you change your elastic search Url from http://localhost:9200/_search to http://yourwebsite/api/Search/_search and let things work as normal. The fragment `[FromBody]SearchDescriptor<dynamic> query` will convert the JSON query into NEST SearchDescriptor. The fragment `client.Search(q => query)` will execute the query. NOTE: `client.Search(query)` will compile but will NOT work.

0 commit comments

Comments
 (0)