Skip to content

Commit

Permalink
fix tables
Browse files Browse the repository at this point in the history
  • Loading branch information
CascadingRadium committed Nov 6, 2023
1 parent 72f7655 commit 1af7916
Showing 1 changed file with 48 additions and 52 deletions.
100 changes: 48 additions & 52 deletions docs/sort_facet.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h2>Purpose of Docvalues</h2>

<h2>Purpose of Docvalues</h2>

<h3>Background</h3>


<p align="justify">What are docValues? In the index mapping, there is an option to enable or disable docValues for a specific field mapping. However, what does it actually mean to activate or deactivate docValues, and how does it impact the end user? This document aims to address these questions.</p>
<pre>
"default_mapping": {
Expand All @@ -24,13 +24,13 @@
]
}
}
</pre>
<p align="justify">Enabling docValues will always result in an increase in the size of your Bleve index, leading to a corresponding increase in disk usage. But what advantages can you expect in return? This document also quantitatively assesses this trade-off with a test case.</p>

<p align="justify">In a more general sense, we recommend enabling docValues on a field mapping if you anticipate queries that involve sorting and/or facet operations on that field. It's important to note, though, that sorting and faceting will work irrespective of whether docValues are enabled or not. This may lead you to wonder if there's any real benefit to enabling docValues since you're allocating extra disk space without an apparent return. The real advantage, however, becomes evident in enhanced query response times and reduced memory consumption during active usage. By accepting a minor increase in the disk space used by your Full-Text Search (FTS) index, you can anticipate better performance in handling search requests that involve sorting and faceting.</p>

<h3>Usage</h3>

</pre>
<p align="justify">Enabling docValues will always result in an increase in the size of your Bleve index, leading to a corresponding increase in disk usage. But what advantages can you expect in return? This document also quantitatively assesses this trade-off with a test case.</p>

<p align="justify">In a more general sense, we recommend enabling docValues on a field mapping if you anticipate queries that involve sorting and/or facet operations on that field. It's important to note, though, that sorting and faceting will work irrespective of whether docValues are enabled or not. This may lead you to wonder if there's any real benefit to enabling docValues since you're allocating extra disk space without an apparent return. The real advantage, however, becomes evident in enhanced query response times and reduced memory consumption during active usage. By accepting a minor increase in the disk space used by your Full-Text Search (FTS) index, you can anticipate better performance in handling search requests that involve sorting and faceting.</p>

<h3>Usage</h3>

<p align="justify">The initial use of docValues comes into play when sorting is involved. In the search request JSON, there is a field named "sort." This optional "sort" field can have a slice of JSON objects as its value. Each JSON object must belong to one of the following types:
<ul>
<li>SortDocID</li>
Expand Down Expand Up @@ -171,19 +171,19 @@
<td>No DocValues used</td>
<td>No DocValues used</td>
<td>No DocValues used</td>
<td>DocValues used for field dolor. Field Mapping for dolor may enable docValues.</td>
<td>DocValues used, for field sit_amet.
Field Mapping for sit_amet may enable docValues.</td>
<td>DocValues used for field "dolor". Field Mapping for "dolor" may enable docValues.</td>
<td>DocValues used, for field "sit_amet".
Field Mapping for "sit_amet" may enable docValues.</td>
</tr>
</table>
</div>
</div>
<p align="justify">Now, let's consider faceting. The search request object also includes another field called "facets," where you can specify a collection of facet requests, with each request being associated with a unique name. Each of these facet requests can fall into one of three types:
<ul>
<li>Date range</li>
<li>Numeric range</li>
<li>Term facet</li>
</ul>
Enabling docValues for the fields associated with such facet requests might provide benefits in this context.</p>
Enabling docValues for the fields associated with such facet requests might provide benefits in this context.</p>
<div style="overflow-x: auto;">
<table>
<tr>
Expand All @@ -208,7 +208,6 @@ Enabling docValues for the fields associated with such facet requests might prov
"size": 10,
"from": 0
}

</pre>
</td>
<td style="vertical-align: top; width: 20%;">
Expand Down Expand Up @@ -240,7 +239,6 @@ Enabling docValues for the fields associated with such facet requests might prov
"size": 10,
"from": 0
}

</pre>
</td>
<td style="vertical-align: top; width: 20%;">
Expand Down Expand Up @@ -299,7 +297,8 @@ Enabling docValues for the fields associated with such facet requests might prov
</tr>
<tr align="center">
<td>No DocValues used</td>
<td colspan="3">DocValues used for field “dolor”. Field Mapping for “dolor” may enable docValues.</td> </tr>
<td colspan="3">DocValues used for field "dolor". Field Mapping for "dolor" may enable docValues.</td>
</tr>
</table>
</div>

Expand Down Expand Up @@ -395,17 +394,17 @@ Enabling docValues for the fields associated with such facet requests might prov
</td>
</tr>
<tr align="center">
<td>DocValues used for field dolor and lorem. Field Mapping for dolor and lorem may enable docValues.</td>
<td>DocValues used for field dolor and ipsum. Field Mapping for dolor and ipsum may enable docValues.</td>
<td>DocValues used for field "dolor" and "lorem". Field Mapping for "dolor" and "lorem" may enable docValues.</td>
<td>DocValues used for field "dolor" and "ipsum". Field Mapping for "dolor" and "ipsum" may enable docValues.</td>
</tr>
</table>
</div>

<h3>Empirical Analysis</h3>

<p align="justify">To evaluate our hypothesis, I've set up a sample dataset on my personal computer and I've created two Bleve indexes: one with docvalues enabled for three fields (<code>dummyDate</code>, <code>dummyNumber</code>, and <code>dummyTerm</code>), and another where I've disabled docValues for the same three fields. These field mappings were incorporated into the Default Mapping. It's important to mention that for both indexes, DocValues for dynamic fields were enabled, as the default mapping is dynamic.</p>

<p align="justify">The values for <code>dummyDate</code> and <code>dummyNumber</code> were configured to increase monotonically, with <code>dummyDate</code> representing a date value and `dummyNumber` representing a numeric value. This setup was intentional to ensure that facet aggregation would consistently result in cache hits and misses, providing a useful testing scenario.</p>
<h3>Empirical Analysis</h3>

<p align="justify">To evaluate our hypothesis, I've set up a sample dataset on my personal computer and I've created two Bleve indexes: one with docvalues enabled for three fields (<code>dummyDate</code>, <code>dummyNumber</code>, and <code>dummyTerm</code>), and another where I've disabled docValues for the same three fields. These field mappings were incorporated into the Default Mapping. It's important to mention that for both indexes, DocValues for dynamic fields were enabled, as the default mapping is dynamic.</p>

<p align="justify">The values for <code>dummyDate</code> and <code>dummyNumber</code> were configured to increase monotonically, with <code>dummyDate</code> representing a date value and `dummyNumber` representing a numeric value. This setup was intentional to ensure that facet aggregation would consistently result in cache hits and misses, providing a useful testing scenario.</p>

<div style="overflow-x: auto;">
<table>
Expand Down Expand Up @@ -546,42 +545,42 @@ Document Format used for the test scenario:
<td style="vertical-align: top; width: 20%;">
<pre>
{
dummyTerm”:”Term,
dummyDate”:”2000-01-01T00:00:00,
dummyNumber:1
"dummyTerm":"Term",
"dummyDate":"2000-01-01T00:00:00,
"dummyNumber:1
}
</pre>
</td>
<td style="vertical-align: top; width: 20%;">
<pre>
{
dummyTerm”:”Term,
dummyDate”:”2000-01-01T01:00:00,
dummyNumber:2
"dummyTerm":"Term",
"dummyDate":"2000-01-01T01:00:00,
"dummyNumber:2
}
</pre>
</td>
<td style="vertical-align: top; width: 20%;">
<pre>
{
dummyTerm”:”Term,
dummyDate”:”2000-01-01T01:00:00+(i hours),
dummyNumber:i
"dummyTerm":"Term",
"dummyDate":"2000-01-01T01:00:00"+(i hours),
"dummyNumber:i
}
</pre>
</td>
<td style="vertical-align: top; width: 20%;">
<pre>
{
dummyTerm”:”Term,
dummyDate:2000-01-01T01:00:00 + (5000 hours),
dummyNumber:5000
"dummyTerm":"Term",
"dummyDate":2000-01-01T01:00:00 + (5000 hours),
"dummyNumber:5000
}
</pre>
</td>
</table>
</div>


<p align="justify">Now I ran the following set of search requests across both the indexes, while increasing the number of documents indexed from 2000 to 4000.</p>

<div style="overflow-x: auto;">
Expand Down Expand Up @@ -630,7 +629,6 @@ Document Format used for the test scenario:
"size": 10,
"from": 0
}

</pre>
</td>
<td style="vertical-align: top; width: 20%;">
Expand Down Expand Up @@ -670,7 +668,6 @@ Document Format used for the test scenario:
"size": 10,
"from": 0
}

</pre>
</td>
<td style="vertical-align: top; width: 20%;">
Expand Down Expand Up @@ -710,7 +707,6 @@ Document Format used for the test scenario:
"size": 10,
"from": 0
}

</pre>
</td>
<td style="vertical-align: top; width: 20%;">
Expand Down Expand Up @@ -753,7 +749,7 @@ Document Format used for the test scenario:
</pre>
</td>
</table>
</div>
</div>


<div style="overflow-x: auto;">
Expand Down Expand Up @@ -782,13 +778,13 @@ Document Format used for the test scenario:
<td align="center"><code>7762.47</code></td>
<td align="center"><code>27.034</code></td>
</tr>
</table>
Even at this small scale, with a small document size and a very limited number of indexed documents, we still observe a noticeable tradeoff. With just a slight increase in the index size (an average of 7KB) we obtain a 20ms reduction in the total execution time, on average, for only 1000 queries.

<h3>Technical Information</h3>

<p align="justify">When a search request involves facet or sorting operations on a field F, these operations occur after the main search query is executed. For instance, if the main query yields a result of 200 documents, the sorting and faceting processes will be applied to these 200 documents. However, the main query result only provides a set of document IDs, not the actual document contents.</p>

<p align="justify">Here's where docValues become essential. If the field mapping for F is docValue enabled, the system can directly access the values for the field from the stored docValue part in the index file. This means that for each document ID returned in the search result, the field values are readily available.</p>

<p align="justify">However, if docValues are not enabled for field F, the system must take a different approach. It needs to "fetch the document" from the index file, read the value for field F, and cache this field-document pair in memory for further processing. The issue becomes apparent in the latter scenario. By not enabling docValues for field F, you essentially retrieve all the documents in the search result (at the worst case), which can be a substantial amount of data. Moreover, you have to cache this information in memory, leading to increased memory usage. As a result, query latency significantly suffers because you're essentially fetching and processing all documents, which can be both time-consuming and resource-intensive. Enabling docValues for the relevant fields is, therefore, a crucial optimization to enhance query performance and reduce memory overhead in such situations.</p>
</table>
Even at this small scale, with a small document size and a very limited number of indexed documents, we still observe a noticeable tradeoff. With just a slight increase in the index size (an average of 7KB) we obtain a 20ms reduction in the total execution time, on average, for only 1000 queries.

<h3>Technical Information</h3>

<p align="justify">When a search request involves facet or sorting operations on a field F, these operations occur after the main search query is executed. For instance, if the main query yields a result of 200 documents, the sorting and faceting processes will be applied to these 200 documents. However, the main query result only provides a set of document IDs, not the actual document contents.</p>

<p align="justify">Here's where docValues become essential. If the field mapping for F is docValue enabled, the system can directly access the values for the field from the stored docValue part in the index file. This means that for each document ID returned in the search result, the field values are readily available.</p>

<p align="justify">However, if docValues are not enabled for field F, the system must take a different approach. It needs to "fetch the document" from the index file, read the value for field F, and cache this field-document pair in memory for further processing. The issue becomes apparent in the latter scenario. By not enabling docValues for field F, you essentially retrieve all the documents in the search result (at the worst case), which can be a substantial amount of data. Moreover, you have to cache this information in memory, leading to increased memory usage. As a result, query latency significantly suffers because you're essentially fetching and processing all documents, which can be both time-consuming and resource-intensive. Enabling docValues for the relevant fields is, therefore, a crucial optimization to enhance query performance and reduce memory overhead in such situations.</p>

0 comments on commit 1af7916

Please sign in to comment.