-
Notifications
You must be signed in to change notification settings - Fork 30
feat: Elastic Search (search-files) API Endpoint #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RSam-NI
wants to merge
18
commits into
master
Choose a base branch
from
users/sam/feat/elastic-search-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c54568a
feat:ElasticSearchAPI
RSam-NI b8181de
fix:BackOffLogic
RSam-NI 7c750cc
fix:Example
RSam-NI 815d50d
fix:AddBackoffDependency
RSam-NI 9180d87
fix:SearchTestPrefix
RSam-NI 43c1051
fix:TestChanges
RSam-NI 86c733d
fix:Test Internal Server Error
RSam-NI cb290b3
fix:Search-API error
RSam-NI 68c52db
feat:AddSkipForLinqQueryFilesRequest
RSam-NI 9db0ab4
fix:PRComments
RSam-NI 266c822
fix:BackofRetryCount
RSam-NI d1edee9
fix:ExampleFile
RSam-NI 8800c3c
fix:PRComments
RSam-NI bfb6191
fix:PRComments
RSam-NI 0d785b6
Merge branch 'master' of https://github.com/ni/nisystemlink-clients-p…
RSam-NI 2607444
fix:PRComments
RSam-NI 31d6f4e
fix:PRComments
RSam-NI d701167
fix:PRComments
RSam-NI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| """Example demonstrating how to search for files using the File API.""" | ||
|
|
||
| import io | ||
| import time | ||
|
|
||
| from nisystemlink.clients.core import HttpConfiguration | ||
| from nisystemlink.clients.file import FileClient, models | ||
| from nisystemlink.clients.file.models import SearchFilesOrderBy, UpdateMetadataRequest | ||
|
|
||
| # Configure connection to SystemLink server | ||
| server_configuration = HttpConfiguration( | ||
| server_uri="https://yourserver.yourcompany.com", | ||
| api_key="YourAPIKeyGeneratedFromSystemLink", | ||
| ) | ||
|
|
||
| client = FileClient(configuration=server_configuration) | ||
|
|
||
| # Upload a test file first | ||
| print("Uploading test file...") | ||
| test_file_content = b"This is a test file for search demonstration." | ||
| test_file = io.BytesIO(test_file_content) | ||
| test_file.name = "search-example-test-file.txt" | ||
|
|
||
| file_id = client.upload_file(file=test_file) | ||
| print(f"Uploaded test file with ID: {file_id}") | ||
|
|
||
| # Wait for the file to be indexed for search | ||
| # Note: Files may take a few seconds to appear in search results after upload | ||
| time.sleep(5) | ||
| print() | ||
|
|
||
| # Example 1: Basic file search with filter - search for the uploaded file | ||
| print("Example 1: Search for the uploaded test file") | ||
| search_request = models.SearchFilesRequest( | ||
| filter='name:("search-example-test-file.txt")', | ||
| skip=0, | ||
| take=10, | ||
| ) | ||
|
|
||
| response = client.search_files(search_request) | ||
| print( | ||
| f"Found {response.total_count.value if response.total_count else 0} file(s) matching the filter" | ||
| ) | ||
| if response.available_files: | ||
| for file in response.available_files: | ||
| if file.properties: | ||
| print( | ||
| f"- {file.properties.get('Name')} (ID: {file.id}, Size: {file.size} bytes)" | ||
| ) | ||
|
|
||
| # Example 2: Search with wildcard pattern | ||
| print("\nExample 2: Search with wildcard pattern") | ||
| search_request = models.SearchFilesRequest( | ||
| filter='name:("search-example*")', | ||
| skip=0, | ||
| take=20, | ||
| order_by=SearchFilesOrderBy.CREATED, | ||
| order_by_descending=True, | ||
| ) | ||
|
|
||
| response = client.search_files(search_request) | ||
| print( | ||
| f"Found {response.total_count.value if response.total_count else 0} file(s) starting with 'search-example'" | ||
| ) | ||
| if response.available_files: | ||
| for file in response.available_files: | ||
| if file.properties: | ||
| print( | ||
| f"- {file.properties.get('Name')} created at {file.created} (Size: {file.size} bytes)" | ||
| ) | ||
|
|
||
| # Example 3: Search by size range | ||
| print("\nExample 3: Search by size range") | ||
RSam-NI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| search_request = models.SearchFilesRequest( | ||
| filter="size:([1 TO 1000])", | ||
| skip=0, | ||
| take=10, | ||
| ) | ||
|
|
||
| response = client.search_files(search_request) | ||
| print( | ||
| f"Found {response.total_count.value if response.total_count else 0} file(s) between 1 and 1000 bytes" | ||
| ) | ||
| if response.available_files: | ||
| for file in response.available_files: | ||
| if file.properties: | ||
| print(f"- {file.properties.get('Name')} (Size: {file.size} bytes)") | ||
|
|
||
| # Example 4: Search by multiple custom properties | ||
| print("\nExample 4: Search by multiple custom properties") | ||
| print("Adding custom properties to existing file...") | ||
|
|
||
| # Update the existing file with custom properties | ||
| custom_metadata = UpdateMetadataRequest( | ||
| replace_existing=False, | ||
| properties={ | ||
| "TestProperty1": "TestValue1", | ||
| "TestProperty2": "TestValue2", | ||
| }, | ||
| ) | ||
| client.update_metadata(metadata=custom_metadata, id=file_id) | ||
|
|
||
| # Wait for indexing | ||
| time.sleep(5) | ||
|
|
||
| # Search by multiple custom properties using AND operator | ||
| search_request = models.SearchFilesRequest( | ||
| filter='(properties.TestProperty1:"TestValue1") AND (properties.TestProperty2:"TestValue2")', | ||
| skip=0, | ||
| take=10, | ||
| ) | ||
|
|
||
| response = client.search_files(search_request) | ||
| print( | ||
| f"Found {response.total_count.value if response.total_count else 0} file(s) with " | ||
| "TestProperty1=TestValue1 AND TestProperty2=TestValue2" | ||
| ) | ||
| if response.available_files: | ||
| for file in response.available_files: | ||
| if file.properties: | ||
| print(f"- {file.properties.get('Name')}") | ||
| print(f" TestProperty1: {file.properties.get('TestProperty1')}") | ||
| print(f" TestProperty2: {file.properties.get('TestProperty2')}") | ||
|
|
||
| # Clean up: delete the test file | ||
| print("\nCleaning up...") | ||
| client.delete_file(id=file_id) | ||
| print(f"Deleted test file with ID: {file_id}") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| from ._file_metadata import FileMetadata | ||
| from ._file_query_order_by import FileQueryOrderBy, FileLinqQueryOrderBy | ||
| from ._file_query_order_by import ( | ||
| FileQueryOrderBy, | ||
| FileLinqQueryOrderBy, | ||
| SearchFilesOrderBy, | ||
| ) | ||
| from ._file_query_response import FileQueryResponse | ||
| from ._link import Link | ||
| from ._operations import V1Operations | ||
| from ._update_metadata import UpdateMetadataRequest | ||
| from ._file_linq_query import FileLinqQueryRequest, FileLinqQueryResponse | ||
| from ._search_files_request import SearchFilesRequest | ||
| from ._search_files_response import SearchFilesResponse | ||
| from ._base_file_response import BaseFileResponse, TotalCount, TotalCountRelation | ||
| from ._base_file_request import BaseFileRequest | ||
|
|
||
| # flake8: noqa |
RSam-NI marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from nisystemlink.clients.core._uplink._json_model import JsonModel | ||
|
|
||
|
|
||
| class BaseFileRequest(JsonModel): | ||
| """Base class for file request models containing common query parameters.""" | ||
|
|
||
| filter: str | None = None | ||
| """ | ||
| Filter string for searching/querying files. | ||
| """ | ||
|
|
||
| skip: int | None = None | ||
| """ | ||
| How many files to skip in the result when paging. | ||
| """ | ||
|
|
||
| take: int | None = None | ||
| """ | ||
| How many files to return in the result. | ||
| """ | ||
|
|
||
| order_by_descending: bool | None = False | ||
| """ | ||
| Whether to sort in descending order. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from enum import Enum | ||
| from typing import List | ||
|
|
||
| from nisystemlink.clients.core._uplink._json_model import JsonModel | ||
|
|
||
| from ._file_metadata import LinqQueryFileMetadata | ||
|
|
||
|
|
||
| class TotalCountRelation(str, Enum): | ||
| """Describes the relation the returned total count value has with respect to the total number of files.""" | ||
|
|
||
| EQUALS = "eq" | ||
| """Equals, meaning that the returned items are all the items that matched the filter.""" | ||
|
|
||
| GREATER_THAN_OR_EQUAL = "gte" | ||
| """Greater or equal, meaning that the take limit has been hit, but there are further items that match the query.""" | ||
|
|
||
|
|
||
| class TotalCount(JsonModel): | ||
santhoshramaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """The total number of files that match the query regardless of skip and take values""" | ||
|
|
||
| relation: TotalCountRelation | ||
RSam-NI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Describes the relation the returned total count value has with respect to the total number of | ||
| files matched by the query. | ||
| """ | ||
|
|
||
| value: int | ||
| """Describes the number of files that were returned as a result of the query in the database""" | ||
|
|
||
|
|
||
| class BaseFileResponse(JsonModel): | ||
| """Base class for file response models containing a list of files and total count.""" | ||
|
|
||
| available_files: List[LinqQueryFileMetadata] | ||
| """The list of files returned by the query""" | ||
|
|
||
| total_count: TotalCount | ||
| """The total number of files that match the query regardless of skip and take values""" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,18 @@ | ||
| from typing import List | ||
|
|
||
| from nisystemlink.clients.core._uplink._json_model import JsonModel | ||
| from nisystemlink.clients.file.models._file_metadata import LinqQueryFileMetadata | ||
| from nisystemlink.clients.file.models._base_file_request import BaseFileRequest | ||
| from nisystemlink.clients.file.models._base_file_response import BaseFileResponse | ||
| from nisystemlink.clients.file.models._file_query_order_by import FileLinqQueryOrderBy | ||
|
|
||
|
|
||
| class FileLinqQueryRequest(JsonModel): | ||
| filter: str | None = None | ||
| """ | ||
| The filter criteria for files. Consists of a string of queries composed using AND/OR operators. | ||
| String values and date strings need to be enclosed in double quotes. Parentheses can be used | ||
| around filters to better define the order of operations. | ||
|
|
||
| Example Filter syntax: '[property name][operator][operand] and [property name][operator][operand]' | ||
| """ | ||
| class FileLinqQueryRequest(BaseFileRequest): | ||
| """Request model for LINQ query operations.""" | ||
|
|
||
| order_by: FileLinqQueryOrderBy | None = None | ||
| """The property by which to order the files in the response.""" | ||
|
|
||
| order_by_descending: bool | None = False | ||
| """If true, the files are ordered in descending order based on the property specified in `order_by`.""" | ||
|
|
||
| take: int | None = None | ||
| """The maximum number of files to return in the response. Default value is 1000""" | ||
|
|
||
|
|
||
| class TotalCount(JsonModel): | ||
| """The total number of files that match the query regardless of skip and take values""" | ||
|
|
||
| relation: str | ||
| """ | ||
| Describes the relation the returned total count value has with respect to the total number of | ||
| files matched by the query. | ||
|
|
||
| Possible values: | ||
|
|
||
| - "eq" -> equals, meaning that the returned items are all the items that matched the filter. | ||
|
|
||
| - "gte" -> greater or equal, meaning that there the take limit has been hit, but there are further | ||
| items that match the query in the database. | ||
| The property by which to order the files in the response. | ||
| """ | ||
|
|
||
| value: int | ||
| """Describes the number of files that were returned as a result of the query in the database""" | ||
|
|
||
|
|
||
| class FileLinqQueryResponse(JsonModel): | ||
| available_files: List[LinqQueryFileMetadata] | ||
| """The list of files returned by the query""" | ||
| class FileLinqQueryResponse(BaseFileResponse): | ||
| """Response model for LINQ query operations.""" | ||
|
|
||
| total_count: TotalCount | ||
| """The total number of files that match the query regardless of skip and take values""" | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from nisystemlink.clients.file.models._base_file_request import BaseFileRequest | ||
| from nisystemlink.clients.file.models._file_query_order_by import SearchFilesOrderBy | ||
|
|
||
|
|
||
| class SearchFilesRequest(BaseFileRequest): | ||
| """Request model for searching files.""" | ||
|
|
||
| order_by: SearchFilesOrderBy | None = None | ||
| """ | ||
| The property by which to order the files in the response. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from ._base_file_response import BaseFileResponse | ||
|
|
||
|
|
||
| class SearchFilesResponse(BaseFileResponse): | ||
| """Response model for search files operation.""" | ||
|
|
||
| pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.