Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 033426f

Browse files
committed
percolate option on index and bulk
1 parent a933c4a commit 033426f

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

guide/reference/api/bulk.textile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ h1. Routing
4848

4949
p. Each bulk item can include the routing value using the @_routing@ field. It automatically follows the behavior of the index / delete operation based on the @_routing@ mapping.
5050

51+
h1. Percolator
52+
53+
p. Each index bulk item can include a percolate value using the @_percolate@ field.
54+
5155
h1. Parent
5256

5357
p. Each bulk item can include the parent value using the @_parent@ field. It automatically follows the behavior of the index / delete operation based on the @_parent@ / @_routing@ mapping.

guide/reference/api/index_.textile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ $ curl -XPUT localhost:9200/blogs/blog_tag/1122?parent=1111 -d '{
128128
}'
129129
</pre>
130130

131+
h1. Percolate
132+
133+
p. "Percolation":percolate.html can be automatically done on an indexed doc by passing the @percolate@ parameter. Setting it to @*@ will cause all percolation queries registered against the index to be checked against the indexed doc, for example:
134+
135+
<pre class="prettyprint">
136+
curl -XPUT localhost:9200/test/type1/1?percolate=* -d '{
137+
"field1" : "value1"
138+
}'
139+
</pre>
140+
141+
p. It can also be set to query (following the query string syntax) to filter out which percolator queries will be executed:
142+
143+
<pre class="prettyprint">
144+
curl -XPUT localhost:9200/test/type1/1?percolate=color:green -d '{
145+
"field1" : "value1",
146+
"field2" : "value2"
147+
}'
148+
</pre>
149+
150+
p. Percolation on index operation is done while optimizing the distributed nature of elasticsearch. Once the index operation is done on the primary shard, it is sent to all the replicas, and while the operation is done on the replicas, the percolation is executed on the node hosting the primary shard. Also, the parsing operation done on the primary shard is reused for the percolation operation.
151+
131152
h1. Distributed
132153

133154
p. The index operation gets hashed into a specific shard id. It then gets redirected into the primary shard within that id group, and replicated (if needed) to shard replicas within that id group.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
layout: guide
3+
title: Percolator API
4+
cat: guide
5+
sidebar: reference_api
6+
---
7+
8+
p. The percolator allows to register queries against an index, and then send @percolate@ requests which include a doc, and getting back the queries that match on that doc out of the set of registered queries.
9+
10+
p. Think of it as the reverse operation of indexing and then searching. Instead of sending docs, indexing them, and then running queries. One sends queries, registers them, and then sends docs and finds out which queries match that doc.
11+
12+
p. As an example, a user can register an interest (a query) on all tweets that contain the word "elasticsearch". For every tweet, one can percolate the tweet against all registered user queries, and find out which ones matched.
13+
14+
p. Here is a quick sample, first, lets create a @test@ index:
15+
16+
<pre class="prettyprint">
17+
curl -XPUT localhost:9200/test
18+
</pre>
19+
20+
p. Next, we will register a percolator query with a specific name called @kuku@ against the @test@ index:
21+
22+
<pre class="prettyprint">
23+
curl -XPUT localhost:9200/_percolator/test/kuku -d '{
24+
"query" : {
25+
"term" : {
26+
"field1" : "value1"
27+
}
28+
}
29+
}'
30+
</pre>
31+
32+
p. And now, we can percolate a document and see which queries match on it (note, its not really indexed!):
33+
34+
<pre class="prettyprint">
35+
curl -XGET localhost:9200/test/type1/_percolate -d '{
36+
"doc" : {
37+
"field1" : "value1"
38+
}
39+
}'
40+
</pre>
41+
42+
p. And the matches are part of the response:
43+
44+
<pre class="prettyprint">
45+
{"ok":true, "matches":["kuku"]}
46+
</pre>
47+
48+
h1. Filtering Executed Queries
49+
50+
p. Since the registered percolator queries are just docs in an index, one can filter the queries that will be used to percolate a doc. For example, we can add a @color@ field to the registered query:
51+
52+
<pre class="prettyprint">
53+
curl -XPUT localhost:9200/_percolator/test/kuku -d '{
54+
"color" : "blue"
55+
"query" : {
56+
"term" : {
57+
"field1" : "value1"
58+
}
59+
}
60+
}'
61+
</pre>
62+
63+
p. And then, we can percolate a doc that only matches on blue colors:
64+
65+
<pre class="prettyprint">
66+
curl -XGET localhost:9200/test/type1/_percolate -d '{
67+
"doc" : {
68+
"field1" : "value1"
69+
},
70+
"query" : {
71+
"term" : {
72+
"color" : "blue"
73+
}
74+
}
75+
}'
76+
</pre>
77+
78+
h1. How it Works
79+
80+
p. The @_percolator@ which holds the repository of registered queries is just a another index. The query is registered under a concrete index that exists (or will exist). That index name is represented as the type in the @_percolator@ index (a bit confusing, I know...).
81+
82+
p. The fact that the queries are stored as docs in another index (@_percolator@) gives us both the persistency nature of it, and the ability to filter out queries to execute using another query.
83+
84+
p. The @_percolator@ index uses the @index.auto_expand_replica@ setting to make sure that each data node will have access locally to the registered queries, allowing for fast query executing to filter out queries to run against a percolated doc.
85+
86+
p. The percolate API uses the whole number of shards as percolating processing "engines", both primaries and replicas. In our above case, if the @test@ index has 2 shards with 1 replica, 4 shards will round robing in handing percolate requests. (dynamically) increasing the number of replicas will increase the number of percolation power.
87+
88+
p. Note, percolate request will prefer to be executed locally, and will not try and round robin across shards if a shard exists locally on a node that received a request (for example, from HTTP). Its important to do some roundrobin in the client code among nodes (in any case its recommended). If this behavior is not desired, the @prefer_local@ parameter can be set to @false@ to disable it.

0 commit comments

Comments
 (0)