From 496ff5d07fa65970a5c5cc2ccd4043f43003aac3 Mon Sep 17 00:00:00 2001
From: Sander Philipse <sander.philipse@elastic.co>
Date: Thu, 21 Nov 2024 17:26:43 +0100
Subject: [PATCH 1/4] [Search] Fix documents count in Search indices page

---
 .../components/result/result_field.tsx                         | 3 +++
 .../public/components/quick_stats/quick_stats.tsx              | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/packages/kbn-search-index-documents/components/result/result_field.tsx b/packages/kbn-search-index-documents/components/result/result_field.tsx
index acd495f71cd44..8f887f52406de 100644
--- a/packages/kbn-search-index-documents/components/result/result_field.tsx
+++ b/packages/kbn-search-index-documents/components/result/result_field.tsx
@@ -85,6 +85,9 @@ export const ResultField: React.FC<ResultFieldProps> = ({
             <EuiPopover
               button={
                 <EuiButtonIcon
+                  aria-label={i18n.translate('searchIndexDocuments.result.fieldTypeAriaLabel', {
+                    defaultMessage: "Show this field's type",
+                  })}
                   onClick={() => setIsPopoverOpen(!isPopoverOpen)}
                   iconType={iconType || (fieldType ? iconMap[fieldType] : defaultToken)}
                 />
diff --git a/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx b/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
index e051fee17d2e2..cc5688fe96de2 100644
--- a/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
+++ b/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
@@ -68,7 +68,7 @@ export const QuickStats: React.FC<QuickStatsProps> = ({ index, mappings, indexDo
   const mappingStats = useMemo(() => countVectorBasedTypesFromMappings(mappings), [mappings]);
   const vectorFieldCount =
     mappingStats.sparse_vector + mappingStats.dense_vector + mappingStats.semantic_text;
-  const docCount = indexDocuments?.results._meta.page.total ?? 0;
+  const docCount = index.documents ?? 0;
 
   return (
     <EuiPanel

From 0e3b664996130969a31aadd9e3b04c71fc455e4e Mon Sep 17 00:00:00 2001
From: Sander Philipse <sander.philipse@elastic.co>
Date: Thu, 21 Nov 2024 18:33:24 +0100
Subject: [PATCH 2/4] Fix i18n

---
 .../components/result/result_field.tsx                   | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/packages/kbn-search-index-documents/components/result/result_field.tsx b/packages/kbn-search-index-documents/components/result/result_field.tsx
index 8f887f52406de..cfc9263cf87fe 100644
--- a/packages/kbn-search-index-documents/components/result/result_field.tsx
+++ b/packages/kbn-search-index-documents/components/result/result_field.tsx
@@ -85,9 +85,12 @@ export const ResultField: React.FC<ResultFieldProps> = ({
             <EuiPopover
               button={
                 <EuiButtonIcon
-                  aria-label={i18n.translate('searchIndexDocuments.result.fieldTypeAriaLabel', {
-                    defaultMessage: "Show this field's type",
-                  })}
+                  aria-label={i18n.translate(
+                    'searchIndexDocuments.result.fieldTypeButtonAriaLabel',
+                    {
+                      defaultMessage: "Show this field's type",
+                    }
+                  )}
                   onClick={() => setIsPopoverOpen(!isPopoverOpen)}
                   iconType={iconType || (fieldType ? iconMap[fieldType] : defaultToken)}
                 />

From 5a2bf85149e7157ec71bfb26b2d7e6309b4de0b6 Mon Sep 17 00:00:00 2001
From: Sander Philipse <sander.philipse@elastic.co>
Date: Thu, 21 Nov 2024 18:39:53 +0100
Subject: [PATCH 3/4] Revert fix

---
 .../public/components/quick_stats/quick_stats.tsx               | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx b/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
index cc5688fe96de2..e051fee17d2e2 100644
--- a/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
+++ b/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
@@ -68,7 +68,7 @@ export const QuickStats: React.FC<QuickStatsProps> = ({ index, mappings, indexDo
   const mappingStats = useMemo(() => countVectorBasedTypesFromMappings(mappings), [mappings]);
   const vectorFieldCount =
     mappingStats.sparse_vector + mappingStats.dense_vector + mappingStats.semantic_text;
-  const docCount = index.documents ?? 0;
+  const docCount = indexDocuments?.results._meta.page.total ?? 0;
 
   return (
     <EuiPanel

From 3a69f470c28f3d898ec02984d4a19639fe8268bd Mon Sep 17 00:00:00 2001
From: Sander Philipse <sander.philipse@elastic.co>
Date: Mon, 25 Nov 2024 14:27:18 +0100
Subject: [PATCH 4/4] [Search] Add tooltip to explain count discrepancy

---
 .../public/components/quick_stats/quick_stat.tsx          | 8 ++++++++
 .../public/components/quick_stats/quick_stats.tsx         | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/x-pack/plugins/search_indices/public/components/quick_stats/quick_stat.tsx b/x-pack/plugins/search_indices/public/components/quick_stats/quick_stat.tsx
index cdd5f12408480..9df28ccec4bd6 100644
--- a/x-pack/plugins/search_indices/public/components/quick_stats/quick_stat.tsx
+++ b/x-pack/plugins/search_indices/public/components/quick_stats/quick_stat.tsx
@@ -18,6 +18,7 @@ import {
   EuiText,
   useEuiTheme,
   useGeneratedHtmlId,
+  EuiIconTip,
 } from '@elastic/eui';
 
 interface BaseQuickStatProps {
@@ -33,6 +34,7 @@ interface BaseQuickStatProps {
   }>;
   setOpen: (open: boolean) => void;
   first?: boolean;
+  tooltipContent?: string;
 }
 
 export const QuickStat: React.FC<BaseQuickStatProps> = ({
@@ -45,6 +47,7 @@ export const QuickStat: React.FC<BaseQuickStatProps> = ({
   secondaryTitle,
   iconColor,
   content,
+  tooltipContent,
   ...rest
 }) => {
   const { euiTheme } = useEuiTheme();
@@ -93,6 +96,11 @@ export const QuickStat: React.FC<BaseQuickStatProps> = ({
                 {secondaryTitle}
               </EuiText>
             </EuiFlexItem>
+            {tooltipContent && (
+              <EuiFlexItem>
+                <EuiIconTip content={tooltipContent} />
+              </EuiFlexItem>
+            )}
           </EuiFlexGroup>
         </EuiPanel>
       }
diff --git a/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx b/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
index e051fee17d2e2..de1ebe0a8dccf 100644
--- a/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
+++ b/x-pack/plugins/search_indices/public/components/quick_stats/quick_stats.tsx
@@ -28,6 +28,7 @@ export interface QuickStatsProps {
   index: Index;
   mappings: Mappings;
   indexDocuments: IndexDocuments;
+  tooltipContent?: string;
 }
 
 export const SetupAISearchButton: React.FC = () => {
@@ -107,6 +108,10 @@ export const QuickStats: React.FC<QuickStatsProps> = ({ index, mappings, indexDo
                 description: index.size ?? '0b',
               },
             ]}
+            tooltipContent={i18n.translate('xpack.searchIndices.quickStats.documentCountTooltip', {
+              defaultMessage:
+                'This excludes nested documents, which Elasticsearch uses internally to store chunks of vectors.',
+            })}
             first
           />
         </EuiFlexItem>