Skip to content

Commit

Permalink
update code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
joemcelroy committed Oct 14, 2024
1 parent 589f746 commit b3b2fed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const JAVASCRIPT_INFO: CodeLanguage = {
codeBlockLanguage: 'javascript',
};

const SERVERLESS_INSTALL_CMD = `npm install @elastic/elasticsearch-serverless`;
const SERVERLESS_INSTALL_CMD = `npm install @elastic/elasticsearch`;

export const JavascriptServerlessCreateIndexExamples: CreateIndexLanguageExamples = {
default: {
Expand All @@ -28,7 +28,7 @@ export const JavascriptServerlessCreateIndexExamples: CreateIndexLanguageExample
elasticsearchURL,
apiKey,
indexName,
}) => `import { Client } from "@elastic/elasticsearch-serverless"
}) => `import { Client } from "@elastic/elasticsearch"
const client = new Client({
node: '${elasticsearchURL}',
Expand All @@ -47,7 +47,7 @@ client.indices.create({
elasticsearchURL,
apiKey,
indexName,
}) => `import { Client } from "@elastic/elasticsearch-serverless"
}) => `import { Client } from "@elastic/elasticsearch"
const client = new Client({
node: '${elasticsearchURL}',
Expand Down
43 changes: 19 additions & 24 deletions x-pack/plugins/search_indices/public/code_examples/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const PYTHON_INFO: CodeLanguage = {
codeBlockLanguage: 'python',
};

const SERVERLESS_PYTHON_INSTALL_CMD = 'pip install elasticsearch-serverless';
const SERVERLESS_PYTHON_INSTALL_CMD = 'pip install elasticsearch';

export const PythonServerlessCreateIndexExamples: CreateIndexLanguageExamples = {
default: {
Expand All @@ -32,7 +32,7 @@ export const PythonServerlessCreateIndexExamples: CreateIndexLanguageExamples =
elasticsearchURL,
apiKey,
indexName,
}: CodeSnippetParameters) => `from elasticsearch-serverless import Elasticsearch
}: CodeSnippetParameters) => `from elasticsearch import Elasticsearch
client = Elasticsearch(
"${elasticsearchURL}",
Expand All @@ -49,21 +49,21 @@ client.indices.create(
elasticsearchURL,
apiKey,
indexName,
}: CodeSnippetParameters) => `from elasticsearch-serverless import Elasticsearch
}: CodeSnippetParameters) => `from elasticsearch import Elasticsearch
client = Elasticsearch(
"${elasticsearchURL}",
api_key="${apiKey ?? API_KEY_PLACEHOLDER}"
"${elasticsearchURL}",
api_key="${apiKey ?? API_KEY_PLACEHOLDER}"
)
client.indices.create(
index="${indexName ?? INDEX_PLACEHOLDER}"
mappings={
"properties": {
"vector": {"type": "dense_vector", "dims": 3 },
"text": {"type": "text"}
}
}
index="${indexName ?? INDEX_PLACEHOLDER}",
mappings={
"properties": {
"vector": {"type": "dense_vector", "dims": 3 },
"text": {"type": "text"}
}
}
)`,
},
};
Expand All @@ -72,7 +72,7 @@ const serverlessIngestionCommand: IngestCodeSnippetFunction = ({
apiKey,
indexName,
sampleDocument,
}) => `from elasticsearch-serverless import Elasticsearch, helpers
}) => `from elasticsearch import Elasticsearch, helpers
client = Elasticsearch(
"${elasticsearchURL}",
Expand All @@ -93,25 +93,20 @@ const serverlessUpdateMappingsCommand: IngestCodeSnippetFunction = ({
apiKey,
indexName,
mappingProperties,
}) => `from elasticsearch-serverless import Elasticsearch
}) => `from elasticsearch import Elasticsearch
client = Elasticsearch(
"${elasticsearchURL}",
api_key="${apiKey ?? API_KEY_PLACEHOLDER}"
"${elasticsearchURL}",
api_key="${apiKey ?? API_KEY_PLACEHOLDER}"
)
index_name = "${indexName}"
mappings = ${JSON.stringify({ properties: mappingProperties }, null, 4)}
update_mapping_response = client.indices.put_mapping(index=index_name, body=mappings)
# Print the response
print(update_mapping_response)
# Verify the mapping
mapping = client.indices.get_mapping(index=index_name)
print(mapping)`;
mapping_response = client.indices.put_mapping(index=index_name, body=mappings)
print(mapping_response)
`;

export const PythonServerlessVectorsIngestDataExample: IngestDataCodeDefinition = {
installCommand: SERVERLESS_PYTHON_INSTALL_CMD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const CodeSample = ({ id, title, language, code, onCodeCopyClick }: CodeS
<strong>{title}</strong>
</EuiText>
<EuiSpacer size="s" />
<EuiThemeProvider colorMode="dark">
<EuiThemeProvider colorMode="INVERSE">
<EuiPanel color="subdued" paddingSize="none" hasShadow={false}>
<div onClick={onCodeClick}>
<EuiCodeBlock
Expand All @@ -54,6 +54,11 @@ export const CodeSample = ({ id, title, language, code, onCodeCopyClick }: CodeS
paddingSize="m"
isCopyable
transparentBackground
css={{
'*::selection': {
backgroundColor: 'rgba(255, 255, 255, 0.2)',
},
}}
>
{code}
</EuiCodeBlock>
Expand Down

0 comments on commit b3b2fed

Please sign in to comment.