Writing MISP restSearch queries that return the right indicators
Teams that feed detection, blocking or reporting tools from MISP need a repeatable way to pull exactly the indicators they can act on. The restSearch endpoint is MISP's query interface for that job: it accepts filters on events, attributes, tags, dates and flags, and returns matching data in a format the calling tool can consume. Query precision matters because a loose filter returns indicators that are stale, unvetted or not meant for enforcement, and those reach blocklists and alerts without an analyst ever reviewing them. A query that is too narrow fails the other way by silently dropping indicators that a control depends on.
MISP exposes an OpenAPI-described API, and restSearch is one of its main operations. The bundled PyMISP library wraps the same API for Python scripts, so a query tested interactively can be moved into a scheduled job without rewriting its logic. The MISP features page lists the export formats MISP supports, including MISP JSON, STIX, OpenIOC, CSV, text, Suricata, Snort, Zeek and RPZ. The same filters apply across these formats, so a team that settles its filter logic once can reuse it for each downstream tool. The reader should still confirm, against the MISP version in use, which parameter names and options the API accepts, because the interface is the authoritative reference for its own instance.
Before a query goes into production, the team should decide what each consumer is allowed to receive. That means deciding whether the consumer needs events or individual attributes, which tags must be included or excluded, how far back the time window reaches, and whether only indicators flagged for detection should pass. Each decision should be tested against a known set of events on a non-production instance and the result counted and reviewed. Repeating that check after each MISP upgrade or change to tagging practice catches silent changes in what the query returns.
Event search or attribute search: choosing the right query scope
An event-level search returns whole MISP events that match your filters, and each returned event carries its attributes, objects, tags, galaxies and event metadata with it. Use this scope when the consumer needs the story around an indicator: who reported it, which campaign it belongs to, what the threat context and sightings look like, and how the event relates to others. Event-level filters work on properties of the event container, such as its tags, its distribution, its organisation, its publish timestamp and its threat level. Because the output is a set of events, a consumer that wants only certain attributes must still filter or discard the rest on its side.
- Filters apply to the container: tag and distribution conditions are evaluated against the event, so an event matching on a tag brings all of its attributes with it.
- Output is nested: each event holds its attributes and objects, which suits enrichment, reporting and sharing whole campaigns.
- Volume grows quickly: large events with many attributes produce large responses, so plan pagination and size limits before running broad searches.
- Attribute-level flags may not narrow the result: an event that matches on tags can still contain attributes you would not want to act on, so check whether to_ids is applied to the event or only to the attributes you then extract.
Before you rely on an event-level query for detection, confirm in your MISP version's API documentation exactly which filters apply at the event level and which are passed down to attributes.
An attribute-level search returns individual attributes, the flat indicator records such as IP addresses, domains, file hashes and URLs, each with its own type, category, value and flags. Use this scope when the consumer is a sensor, firewall, DNS resolver or other tool that needs a list of values and has no use for surrounding context. Filters such as type, category and to_ids apply directly to each attribute, which makes this the more precise scope for producing blocklists and detection content. The trade-off is that you lose the event narrative unless you request it back in a separate query.
- Type and category filters are direct: you can ask for
ip-dstordomainvalues in a given category without pulling unrelated attributes. - to_ids narrows detection content: attributes flagged for detection are the ones intended for automated use, so filter on that flag when feeding enforcement tools.
- Context is lost: the returned attributes do not explain their campaign or source, so store the event identifier with each value if you may need to trace it back.
- Attribute distribution still matters: an attribute can carry its own distribution setting, which may restrict it even when the parent event is shareable, so confirm how your version applies it.
Test the attribute query on a known event before deployment, and confirm in your version's API documentation which attribute-level filters are supported and how they combine.
The right scope depends on what the consumer does with the result. A human analyst who investigates a campaign usually needs event-level output, because the relationships, objects and sightings explain why an indicator matters. An automated consumer that blocks or alerts usually needs attribute-level output, because it acts on values and flags rather than narratives. Many teams run both: an attribute-level pull feeds the enforcement tool, and a separate event-level pull feeds the analysts' workspace or the reporting pipeline. Separating the two keeps detection content small and predictable while preserving context for investigation.
- Analyst workflow (illustrative): a team triaging a phishing campaign needs the event, its tags and its related objects to decide scope.
- Blocking workflow (illustrative): a DNS resolver needs domain values flagged for detection, with no event text attached.
- Mixed workflow: an enrichment job may start from attributes, then fetch the parent event only for values it intends to keep.
- Cost of the wrong choice: event-level pulls into a blocking tool add noise and size, while attribute-only pulls into analysis lose the links analysts need.
Write down the consumer, its required fields and its required context before writing any query, and confirm the chosen scope against your MISP version's API documentation.
Event-level metadata and attribute-level fields interact in ways that are easy to misread. Tags and distribution usually sit on the event, while to_ids, type and category sit on the attribute. A query that combines both can return an attribute only when the parent event passes the event-level condition and the attribute passes its own condition. Distribution deserves particular care because it governs who may receive the data, so a broad query can return attributes a consumer is not entitled to see if the sharing model is misunderstood. Verify the combined behavior with test events before relying on it for production enforcement.
- Two levels of conditions: an event tag condition and an attribute to_ids condition both have to hold for an attribute to appear in an attribute-scoped result, so confirm the exact combination in your version.
- Distribution is an access control: check that the consumer's organisation is entitled to every event and attribute the query returns.
- Tags are not a substitute for to_ids: a tag such as a TLP marking describes sharing or confidence, while to_ids controls whether an attribute is meant for detection.
- Test with known data: create a small event with mixed flags and confirm which attributes each query returns.
Record the tested behavior in your runbook and rerun the same test after each MISP upgrade, since filter handling can change between releases.
Query options and when each one fits
This table compares the restSearch parameter groups a team adjusts most often, with the use case and main risk for each. Read it as a checklist before running a query against production data, and confirm exact parameter names in the API reference for your MISP version.
| Option group | When it fits | Main risk |
|---|---|---|
| Tag logic (AND, OR, NOT) | AND narrows to events carrying every listed tag; OR widens across related tags; NOT excludes known noise such as a TLP label or an internal-only marker | An OR list that is too broad returns unrelated intelligence, and a NOT filter can silently drop events that carry a sensitive tag you did not intend to exclude |
| Time windows | Pulls limited to recent activity for scheduled jobs, or a bounded range for an incident review | Windows based on event date rather than attribute or publish date can miss late-added indicators, so check which timestamp the filter uses |
| to_ids | Restricts results to attributes flagged for detection, used for feeding sensors, firewalls and blocklists | Attributes without the flag are excluded silently, so a context-only query returns less than the analyst expects |
| Type and category filters | Narrows to domains, IP addresses, file hashes or a specific category such as network activity | A narrow type filter can hide indicators stored under a different type or category, and a broad one returns high-volume noise |
| Event versus attribute search | Event search returns whole events for context; attribute search returns individual indicators for detection content | Attribute search without context loses the event details that explain why an indicator matters |
| Include options | Adds related data such as tags, objects or sightings when a downstream tool needs them | Each extra include increases response size and processing time on large result sets |
| Warninglist enforcement | Excludes well-known benign values such as public DNS resolvers or major cloud domains before export | Skipping enforcement pushes false positives into blocklists, and the warninglist set must match your deployment |
| Output format | JSON for pipelines and conversion tools, text or CSV formats for lightweight sensor lists | Format-specific exports may omit fields that the consuming tool requires, so test each target |
Building and testing a restSearch query step by step
This sequence moves a restSearch query from a narrow, verified test to a paginated pull that an automation job can run safely. Each step ends with a check so the team knows the query returns what the analyst expects before it is scheduled.
Confirm the API key scope and server version
Before writing any query, the engineer confirms which MISP server version is running and which user account the API key belongs to. The key's role determines which events, attributes and tags come back, so a query that looks wrong may simply be hitting a restricted view. Check the server version against the API documentation served by the instance, and record the role and organization tied to the key. The step is done when the engineer can state, in writing, which records this key should be able to see. Use a dedicated read-only key for the query rather than an analyst's personal key.
Run a narrow query on one tag and one time window
Start with a single tag and a short, recent time window, asking restSearch for one event type, such as events rather than attributes, so the scope is easy to reason about. Keep the request body minimal and log the exact JSON sent. The output is a small set of records whose tags and timestamps can be checked by hand. If the query returns nothing, widen the window once to see whether the tag name or the time field is the cause before changing anything else.
Check the count and sample records against the interface
Compare the number returned by the query with the same filter applied in the MISP web interface, and open two or three sample records to confirm their tags, timestamps and distribution match what the query selected. A mismatch usually points to a key scope difference, a tag that is spelled differently, or a publish-state assumption. The step is complete when the counts agree and the samples confirm the filter logic. For a stronger check, use a known test event that you created with a unique tag so the expected result is exactly one record.
Test tag logic with NOT and OR conditions
Add exclusion and alternative tags one at a time, rerunning the count after each change. Use a test event that carries a known combination of tags so you can predict whether it should appear. An OR condition that returns more records than the sum of its parts, or a NOT condition that removes too much, is a sign the tag list is being read differently than intended. The output is a short set of test cases with expected and actual results, which you keep with the query definition.
Add to_ids and warninglist handling
Next, add the to_ids filter if the query feeds detection or blocking, and decide how warninglist matches are handled. Warninglists flag values that are common or benign, such as well-known public domains, so the query should either exclude flagged values or pass them to a review step. Confirm the warninglist behavior on your own instance, since enforcement options depend on the query form and version. Verify by comparing a flagged sample value with and without the filter and confirming the output matches the rule you chose.
Add include options and verify the returned fields
Add only the include options the job needs, such as attribute detail, tags or related objects, because each addition changes the response size and the parsing code. Inspect the raw response for one record and confirm every field the downstream script reads is present and correctly typed. Missing fields often appear only when an include option is absent, so test the parser against a record that has no tags or no objects, not just a complete one.
Paginate and run an incremental pull on a test instance
Add pagination with a fixed page size, and confirm that paging through the full result set returns the same total count as the unpaginated query. Then test an incremental pull by saving the last timestamp and running a second request that should return only newer records. Run the whole sequence on a non-production instance or a copy of the data first, and confirm that re-running the job does not duplicate or skip records. Only after these checks pass should the query be placed in a scheduled job, with the saved query definition and test results stored alongside it.
Enforcing warninglists so noisy indicators stay out of results
Warninglists flag values that commonly cause false positives, such as public DNS resolvers or well-known update domains. Where you enforce them decides who handles those matches, how consistently they are handled, and how much work lands on your consuming scripts and detection tools.
What warninglists check
A warninglist is a list of values, such as popular domains, public resolver addresses and common file hashes, that appear in legitimate traffic and should rarely be blocked. MISP matches attributes against these lists and marks hits so analysts can see them. The lists come from the MISP project, and their content changes over time. Confirm which lists are enabled on your instance, and review how each one is configured, before relying on them in blocking workflows.
MISP featuresEnforcing in the query
Filtering in restSearch with the warninglist-related options keeps flagged values out of the response before your script sees them. This is the most consistent point, because every consumer of that query gets the same result. The trade-off is that a filter that is too broad can hide genuine indicators, so test each query against a sample event and confirm the flagged values you expect to see are still reported in the analyst view.
Enforcing in the consuming script
Your PyMISP script or scheduled job can check warninglist hits itself and drop or quarantine matching values before export. This keeps the query simple and lets the script log every exclusion for review. The cost is that each consumer must implement the same logic, and a new script that skips the check can push noisy indicators downstream. Keep the logic in one shared function and record the warninglist version it used.
Enforcing in the downstream tool
Firewalls, SIEMs and EDR platforms often have their own allowlists and exception handling. Relying on them moves the decision to the team that owns detection, which can be useful when it already maintains tuned allowlists. The risk is that MISP-fed rules then block values that MISP itself would have flagged, and the two lists drift apart. Confirm which layer owns each exception and who approves changes.
Choosing a layered approach
Most teams combine two points: a query-level filter for the bulk export feeding blocking, and a script-level check that logs what was removed. The query keeps output small and predictable, while the script records exceptions for audit. Document which layer handles each feed, and review exclusions after each list update so that a removed indicator is never silently lost.
Reviewing exclusions after updates
Warninglist content changes, and a value that was noisy last quarter may now be a valid indicator, or the reverse. Schedule a review of what each enforcement point excluded, compare counts before and after an update, and sample removed values with the analysts who own the feed. Ask your MISP administrator how warninglist updates are applied on your instance and who signs off on changes to enabled lists.
How a restSearch request moves from script to filtered indicators
The request starts in an automation script or PyMISP client that sends a POST to the restSearch endpoint with an API key in the header. MISP checks the key and the user's role before any filter runs, so the same query can return different results for different accounts. Filters, optional warninglist and to_ids handling, and pagination shape the result set, which the script then passes to a detection or blocking tool. Check the trust boundary at the point where indicators leave the MISP instance, because data past that line is no longer controlled by MISP's access model.
The trust boundary sits between the MISP instance and downstream detection or blocking systems.
Pagination and incremental pulls without missing or duplicating data
A restSearch pull is only as reliable as the checkpoint it resumes from. Large restSearch result sets have to be fetched in pages, and each run should only request what changed since the last successful run. Both goals fail quietly if the query logic also decides where the next run starts. Keep the checkpoint (the last timestamp or event identifier you fully processed) in a separate store that your job reads at start and writes only after the batch has been stored and verified. Pagination should walk a fixed, documented query so that a retried page returns the same records. Confirm on your own instance how your MISP version orders results and how the page parameter behaves before you rely on it, because page sizes and any server-side limits vary by deployment and version and should not be assumed.
Incremental pulls carry three specific risks. Clock skew between your job host and the MISP server can push a window boundary past records that were written moments earlier, so the lower bound should be taken from the server's own timestamps and the window should overlap the previous one by a small, deliberate margin. That overlap produces duplicates, so the import side must be idempotent, keyed on the event UUID and attribute UUID, with the timestamp and published fields compared before an update is applied. The third risk is edits. An event can be changed after it was pulled, and a window based on creation time will not return it again, so use the modification timestamp for the filter and confirm that your queries filter on it. Deletions and unpublished changes also need a documented policy, since a pull may not show them the way a sync does.
Schedule a reconciliation job separately from the incremental job. Periodically compare counts and identifiers for a bounded window between MISP and your local store, and investigate any gap before advancing the checkpoint again. Ask the administrator of your instance to confirm which fields and filters the reconciliation query supports, and record the exact query and count in your run log so that a discrepancy can be reproduced. Treat the first full backfill as a separate, one-time job with its own checkpoint, so that a failure in history does not reset ongoing collection.
Security considerations for API keys, scopes and shared results
A restSearch query runs with the permissions of the API key that makes it, so the key, its runtime and its sharing context decide what a script can see. The cards below cover the decisions that connect query design to access control, and they point to the wider MISP hardening work rather than repeating it.
Scope a read-only key for query scripts
Give each query script its own API key tied to a dedicated user account with a read-only role, instead of reusing an analyst or administrator key. Check the role's permissions in your own instance, since role names and capabilities are set locally. A key that can only search and read limits the damage if a script is copied, logged or misconfigured. Ask whether the account's organization and sharing group membership match what the script is meant to reach.
Protect keys in the automation runtime
Keep the API key out of script source, shell history, cron files and container images. Load it at runtime from a secrets store or an environment file with restricted read permissions, and rotate it when a person or system with access leaves. Scheduled restSearch jobs often run on hosts with broader access than the query needs, so review which service account owns the cron entry and what else that account can reach.
Log query activity and review it
Record which key ran which restSearch query, when, and how many results it returned. MISP's audit trail is the first place to check when an export shows more than expected. Review logs for unfamiliar keys, queries that use broad filters with no tag or time window, and repeated full pulls from a key that normally runs incremental jobs. Confirm with your MISP version how long audit entries are kept and where they can be forwarded.
Respect distribution levels in results
restSearch returns only the events and attributes the calling user is allowed to see under their organization's sharing rules, including distribution levels and sharing groups. A query that looks complete from a broad key can still miss material, and a result set saved to a file or sent to a chat channel can expose data beyond the original caller's permissions. Decide where exported results may go before a script writes them anywhere.
MISP featuresControl where exported results travel
Treat each saved query output as a new copy of shared intelligence with its own handling rules. Store exports in locations with the same access controls as the source, avoid pushing raw results into public or broadly shared channels, and strip or redact fields that carry internal context before forwarding. Document which downstream tools receive the output so that a revoked sharing agreement can be traced to every copy.
Tie key controls to hardening work
Scoped keys, runtime secret handling and audit logging are part of a wider MISP hardening program covering roles, MFA, blocklists and advisories. Keep this page focused on the query path, and use the hardening guidance to set instance-wide controls. Ask your implementation partner or internal team to confirm which of these settings apply to your MISP version before you publish a query script.
Questions teams ask before writing MISP restSearch queries
Can an in-house engineer write MISP restSearch queries without outside help?
Yes, a Python or API-literate engineer with access to a MISP instance can write restSearch queries, and the API is documented in the OpenAPI description bundled with MISP. The harder part is not the request syntax but knowing which attributes, tags and warninglist behavior your consumers need. Engineers who understand their own detection stack and have an admin who can create a dedicated API key usually reach a working query set faster. Confirm the exact endpoints and parameters against the OpenAPI description on your MISP version before you build on them, because behavior can change between releases.
How long does initial restSearch query design usually take?
The duration depends mostly on how many sources feed the queries and how many consumers rely on the results. A single consumer pulling one event type from one instance is a small task. Several downstream tools, each with different to_ids rules, time windows and tag filters, add test cycles for every pairing. No duration has been set for this work here, so ask any provider for a timeline tied to a written list of sources, consumers and query types. Fixed-scope engagements are agreed in writing before work starts, which gives you that list as a basis for comparison.
What does the team need to provide for a restSearch query project?
The work goes faster when the team provides a few specific inputs:
- MISP admin access or a named admin who can create API keys with suitable roles.
- Sample data: representative events, attributes, tags and the sightings or feeds you expect to query.
- A test instance, so queries can be run and timed without affecting production sync or publishing.
- A named owner who signs off on which indicators each consumer should receive.
Without a named owner, requirements about to_ids, tag exclusions and warninglist handling tend to stay unresolved until the first false positive appears in a sensor.
When should a team bring in a partner for MISP query design?
A partner is worth considering when several consumers need different outputs from the same instance, when the team lacks time to test queries against real data, or when query results feed blocking controls where mistakes are costly. It is also sensible when you plan an upgrade and need existing queries revalidated. DeployOpen implements and documents self-hosted open-source platforms in the client's own infrastructure and can scope query design as part of a fixed-scope engagement. Your internal team keeps ownership of the sharing policy, which a partner should help you document rather than decide for you.
What drives the cost of MISP restSearch query work?
Cost follows the amount of decision-making and testing, not the request syntax itself. The main drivers are:
- The number of consumers, since each one needs its own filters, output format and test pass.
- The warninglist and to_ids policy, which determines what is safe to block on.
- Incremental pull logic, including time windows, pagination and handling of changed or deleted records.
- Testing against a realistic dataset and checking results after each MISP update.
Ask any provider for a quote that lists each consumer, each query and each test case separately. No prices are set on this page, and a quote should follow from that written scope.
Which MISP restSearch queries need revalidation after an upgrade?
Any query that depends on filters, output formats or defaults can change behavior after an upgrade, so it should be retested. Priorities are queries that feed blocking or detection, incremental pulls that rely on timestamps, and exports used by STIX or other converters. The MISP 2.5 line is the recommended version for new deployments, and recent releases such as 2.5.47 introduced a new database migration system with PostgreSQL support, so check the release notes for your target version before you upgrade. Keep a saved set of test queries with expected result counts so regressions are visible quickly.
Does the MISP restSearch query work carry recurring effort after launch?
Yes, the work recurs in a few predictable places. Queries need revalidation after MISP upgrades, when consumers change their requirements, and when new taxonomies, galaxies or warninglists are adopted. Sharing communities can also change tag conventions, which affects exclusion logic. Ownership of the query set should stay with a named internal person, who reviews failures and approves changes. Optional retainers for ongoing support, upgrades and continuous testing are available from DeployOpen, and the scope of any retainer is agreed in writing.
Which security checks should apply to MISP API keys used for queries?
Use a dedicated API key for each script or consumer rather than a personal admin key, and give it the minimum role needed to read the events it queries. Keys that only read should not be able to publish or modify events. Record which consumer uses which key so revocation is simple when a tool is retired. Store keys in your secrets manager, not in scripts or query files. Your MISP hardening controls, including MFA on human accounts and logging of API use, should be reviewed alongside the query design, and you should confirm the exact role settings against your MISP version.
Deciding between event search, attribute search and a bulk export
The decision starts with the consumer's need. If the consumer needs surrounding context such as the event, its tags, galaxies and sharing group, search events. If it needs flat indicators only, search attributes. If the output must match a standard format such as STIX or Suricata, export through the matching format. If the same query will run repeatedly, check whether the volume justifies a scheduled incremental pull instead of a full re-export. Check to_ids and warninglist handling on every branch before you publish the result.
Decision path for choosing the restSearch query type and output for a consumer.
How DeployOpen scopes and delivers MISP query automation
DeployOpen plans and builds restSearch queries and filters for MISP inside infrastructure you control, starting from the intelligence questions your teams need answered. Each engagement is fixed-scope, with the query set, filters, tests and handover agreed in writing before work starts.
How we scope
- Inventory the detection, reporting and sharing questions that restSearch queries must answer for your teams.
- Define which MISP instance, API key scope and roles the queries will run under, and who approves them.
- Agree in writing which filters, tag logic, time windows and export formats are in the fixed scope.
How we build
- Write and test event-level and attribute-level restSearch queries, checking to_ids, tag exclusions and warninglist behavior against sample data.
- Build pagination and incremental pull logic so repeated runs return only new or changed records.
- Review query results with your analysts to confirm noise, correlation load and output shape before they are used.
How we hand over
- Document each query with its purpose, parameters, expected output and known limits in a form your team can maintain.
- Provide a test set and retest steps so your team can confirm queries still return the right indicators after changes.
- Walk your operators through running, adjusting and troubleshooting the queries without DeployOpen involvement.
How we support
- Support after handover is available as a retainer, covering query fixes and changes when your MISP version or data changes.
- Retainers can include retesting queries after MISP upgrades, so you can confirm results match the agreed scope.
- Ask for the support terms, response expectations and change process in your quote before the engagement starts.

