Search

InsightMaker.search(query, dataset=None, fields=None, size=100, raw=False)

Parameters:

NameTypeDescription

query

String, dict or insight_maker.api. query_builders. SubQuery

InsightMaker Query, can either be a Lucene Syntax query string, Elasticsearch Query DSL as a python dictionary (starting at bool), or a SubQuery (or decedent) object from insight_maker.api.query_builders (wrappers for Query DSL)

dataset

string, Dataset or list

Optional - Dataset object, dataset name string, or list of either

fields

list

Optional – List of field ids of Field objects

size

integer

Number of results to return (default 100)

raw

boolean

Default False, if true, returns the raw REST JSON response as a python dictionary.

Response:

A DataSample object, properties:

  • DataSample.df A pandas DataFrame object containing all results

  • DataSample.scroll_id The scroll ID required for a scroll search

Example:

Below is an example of a simple string query, these use Lucene Syntax or more simply, they behave in same way as the search box in the enterprise search app. An asterisk will return all documents.

results = im.search("*", dataset = "sharepoint")
print(results.df)

Alternatively, a python dictionary can be used to store an Elastic Query DSL JSON query. This is the most complex, but also most flexible way to query InsightMaker. For example:

query = {
    "bool": {
        "must":
            [
                {
                    "range": {"size": {"gte": 1000, "lt": 2000}}
                },
                {
                    "bool":
                        {
                            "must_not": [{"regexp": {"name": {"value": ".*\\.txt"}}}]
                        }
                }
            ]
    }
}

results = im.search(query, dataset = "documents", size = 10)
print(results.df)