Skip to content

Commit 036b072

Browse files
committed
finished documentating all the section under search
1 parent ce656d4 commit 036b072

13 files changed

+200
-26
lines changed

new_docs/contents/search/basics.markdown

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,64 @@ menuitem: basics
66
---
77

88

9-
# Documentation still in progress
9+
# From/Size
10+
11+
s.From(120).Size(20);
12+
13+
this is also valid
14+
15+
.Skip(120).Take(20)
16+
17+
# Indices / Types
18+
You can explicitly tell NEST to use multiple indices:
19+
20+
client.Search<MyObject>(s=>s
21+
.Indices(new [] {"Index_A", "Index_B"})
22+
...
23+
)
24+
25+
If you want to search across all indices
26+
27+
client.Search<MyObject>(s=>s
28+
.AllIndices()
29+
...
30+
)
31+
32+
Or if you want to search one index (thats not the default index)
33+
34+
client.Search<MyObject>(s=>s.
35+
.Index("Index_A")
36+
...
37+
)
38+
39+
Remember since elasticsearch 19.8 you can also specify wildcards on index names
40+
41+
client.Search<MyObject>(s=>s
42+
.Index("Index_*")
43+
...
44+
)
45+
.Types(new [] { typeof(ElasticSearchProject)})
46+
47+
## Covariance
48+
You can make C# covariance work for you by typing the search to a common baseclass (can be object)
49+
50+
i.e:
51+
52+
.Search<object>(s=>s
53+
.Types(typeof(Product),typeof(Category),typeof(Manufacturer))
54+
.Query(...)
55+
);
56+
57+
This will search on `/yourdefaultindex/products,categories,manufacturers/_search` and setup a default `ConcreteTypeSelector` that understands what type each returned document is.
58+
59+
Using
60+
61+
.ConcreteTypeSelector(Func<dynamic, Hit<dynamic>, Type>)
62+
63+
you can manually specify the type of each hit based on some json value (on dynamic) or on the hit metadata.
64+
65+
#Routing
66+
You can specify the routing for the search request using
67+
68+
.Routing("routevalue")
1069

11-
This is sadly still a marker file.

new_docs/contents/search/explain.markdown

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ menuitem: explain
66
---
77

88

9-
# Documentation still in progress
9+
# Explain
1010

11-
This is sadly still a marker file.
11+
Using explain you'll get more an explanation of each hits score
12+
13+
You can enable it by calling
14+
15+
.Explain()
16+
17+
On your search request.
1218

new_docs/contents/search/fields.markdown

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ menuitem: fields
66
---
77

88

9-
# Documentation still in progress
9+
# Fields
1010

11-
This is sadly still a marker file.
11+
Quite often you don't need to waste bandwidth by returning the complete object graph foreach hit.
12+
13+
Using
14+
15+
.Fields(p=>p.Id, p=>p.Name, p=>p.Followers.First().Name, ...)
16+
17+
You can limit the returned fields for each hit.
18+
19+
An overload taking plain strings also exists
1220

new_docs/contents/search/highlighting.markdown

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,29 @@ menuitem: highlighting
66
---
77

88

9-
# Documentation still in progress
9+
# Highlighting
1010

11-
This is sadly still a marker file.
11+
Using highlighting you can return the relavent parts of a field and using highlighted markers indicating why a document matched.
1212

13+
var result = this._client.Search<ElasticSearchProject>(s => s
14+
.From(0)
15+
.Size(10)
16+
.Query(q => q
17+
.QueryString(qs => qs
18+
.OnField(e => e.Content)
19+
.Query("null or null*")
20+
)
21+
)
22+
.Highlight(h => h
23+
.PreTags("<b>")
24+
.PostTags("</b>")
25+
.OnFields(f => f
26+
.OnField(e => e.Content)
27+
.PreTags("<em>")
28+
.PostTags("</em>")
29+
)
30+
)
31+
);
32+
33+
Please take note that this wont alter the contents of the results `.Documents` but the results will have a separate bucket
34+
that contains each highlight result(s) for each hit on `result.Highlights`.

new_docs/contents/search/index-boost.markdown

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ menuitem: index-boost
66
---
77

88

9-
# Documentation still in progress
9+
# Index boost
1010

11-
This is sadly still a marker file.
11+
An index boost allows you to boost hits if they originate from a certain index
12+
13+
var s = new SearchDescriptor<ElasticSearchProject>()
14+
.Skip(0)
15+
.Take(10)
16+
.Explain()
17+
.Version()
18+
.MinScore(0.4)
19+
.IndicesBoost(b => b.Add("index1", 1.4).Add("index2", 1.3));
20+
1221

new_docs/contents/search/named-filters.markdown

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ menuitem: named-filters
66
---
77

88

9-
# Documentation still in progress
9+
# Named Filters
1010

11-
This is sadly still a marker file.
11+
Each filter allows you specify a name i.e
12+
13+
.Filter(f=>f.Name("myfilter").Term(...))
14+
15+
This will allow you to see on each with which filter applied to it.
16+
17+
Right now I'm waiting on this active elasticsearch issue to complete mapping this functionality
18+
19+
https://github.com/elasticsearch/elasticsearch/issues/3097
1220

new_docs/contents/search/preference.markdown

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@ menuitem: preference
66
---
77

88

9-
# Documentation still in progress
9+
# Preference
1010

11-
This is sadly still a marker file.
11+
Signals on what node to execute the search
12+
13+
You can call the following methods on `SearchDescriptor`
14+
15+
.Preference("my_custom_preference")
16+
17+
18+
.ExecuteOnPrimary()
19+
20+
21+
.ExecuteOnLocalShard
22+
23+
24+
.ExecuteOnNode("mynodename")
1225

new_docs/contents/search/script-fields.markdown

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,22 @@ menuitem: script-fields
66
---
77

88

9-
# Documentation still in progress
10-
11-
This is sadly still a marker file.
9+
# Script fields
1210

11+
var queryResults = this._client.Search<ElasticSearchProject>(s=>s
12+
.From(0)
13+
.Size(10)
14+
.MatchAll()
15+
.Fields(f=>f.Name)
16+
.ScriptFields(sf=>sf
17+
.Add("locscriptfield", sff=>sff
18+
.Script("doc['loc'].value * multiplier")
19+
.Params(sp=>sp
20+
.Add("multiplier", 4)
21+
)
22+
)
23+
)
24+
);
25+
Assert.True(queryResults.IsValid);
26+
Assert.True(queryResults.Documents.Any());
27+
Assert.True(queryResults.Documents.All(d=>d.LocScriptField != 0));

new_docs/contents/search/scroll.markdown

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,30 @@ menusection: search
55
menuitem: scroll
66
---
77

8+
# Scroll
89

9-
# Documentation still in progress
10+
The scroll api allows you to efficiently page through a large dataset as it keeps the query alive in the cluster.
1011

11-
This is sadly still a marker file.
12+
var scanResults = this._client.Search<ElasticSearchProject>(s => s
13+
.From(0)
14+
.Size(1)
15+
.MatchAll()
16+
.Fields(f => f.Name)
17+
.SearchType(Nest.SearchType.Scan)
18+
.Scroll("2s")
19+
);
20+
Assert.True(scanResults.IsValid);
21+
Assert.False(scanResults.Documents.Any());
22+
Assert.IsNotNullOrEmpty(scanResults.ScrollId);
1223

24+
var scrolls = 0;
25+
var results = this._client.Scroll<ElasticSearchProject>("4s", scanResults.ScrollId);
26+
while (results.Documents.Any())
27+
{
28+
Assert.True(results.IsValid);
29+
Assert.True(results.Documents.Any());
30+
Assert.IsNotNullOrEmpty(results.ScrollId);
31+
results = this._client.Scroll<ElasticSearchProject>("4s", results.ScrollId);
32+
scrolls++;
33+
}
34+
Assert.AreEqual(18, scrolls);

new_docs/contents/search/search-type.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ menuitem: search-type
66
---
77

88

9-
# Documentation still in progress
9+
# Search Types
1010

11-
This is sadly still a marker file.
11+
There are different execution paths that can be done when executing a distributed search.
12+
13+
.SearchType(SearchType.Scan)
1214

0 commit comments

Comments
 (0)