# Merge, Dedupe & Transform Datasets (`solidactors/merge-dedupe-datasets`) Actor

Merge any number of Apify datasets, remove duplicates by your own fields (exact, normalised or fuzzy), keep the first, last or most complete copy, filter and reshape items. Streams page by page, so millions of items work.

- **URL**: https://apify.com/solidactors/merge-dedupe-datasets.md
- **Developed by:** [Solid Actors](https://apify.com/solidactors) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.03 / 1,000 output items

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Merge, Dedupe & Transform Datasets

Merge any number of Apify datasets into one clean dataset. Remove duplicates by the fields you choose, with exact, normalised or fuzzy matching. Keep the first, the last or the most complete copy. Filter, keep, drop and rename fields on the way. Datasets are streamed page by page, so a few hundred items or several million behave the same.

### What it does

- **Merge** several datasets in the order you give (for example the outputs of 10 scraper runs).
- **Dedupe by your key**: `url`, `email`, `name + city`, nested fields like `address.city`, or the whole item.
- **Choose the survivor**: `first` found, `last` found (newest data wins), or `mostComplete` (the copy with the most filled-in fields).
- **Normalise before comparing**: ignore case, accents, extra spaces; normalise URLs (http/https, `www.`, trailing slash, `#anchor`, `utm_` and click-id parameters); digits only (phone numbers).
- **Fuzzy matching** on a text field, for example company names `Acme Inc` vs `ACME, Inc.`, with a similarity threshold and optional blocking fields (only compare items in the same city or country).
- **Filter** without code: `{"field": "price", "op": "gt", "value": 10}`. Ops: `eq`, `ne`, `contains`, `notContains`, `gt`, `gte`, `lt`, `lte`, `exists`, `notExists`, `regex`, `in`.
- **Reshape**: keep only some fields, drop fields, rename fields, add the source dataset ID.
- **Output** to the run's dataset, a named dataset, or append to an existing dataset.

### Why this one

- **It finishes.** Items are read in pages (10,000 by default) and only a 16-byte fingerprint per key stays in memory, so large merges do not run out of memory.
- **Permissions handled.** The dataset fields use Apify's dataset picker, which grants this run read access to exactly the datasets you choose. No "insufficient permissions" failures, no need to give the Actor full access to your account.
- **Clear summary.** Items read, kept, duplicates removed (exact and fuzzy), filtered out, and the same per dataset, in the `SUMMARY` record.

### Input example

```json
{
  "datasetIds": ["aBcD1234efgh", "XyZ987654321"],
  "dedupFields": ["url"],
  "normalizeUrls": true,
  "keepWhich": "mostComplete",
  "filters": [{ "field": "price", "op": "gt", "value": 0 }],
  "fieldsToDrop": ["debug"],
  "renameMap": { "title": "name" },
  "addSourceDatasetId": true
}
```

Fuzzy company names inside each city:

```json
{
  "datasetIds": ["aBcD1234efgh"],
  "dedupFields": ["website"],
  "normalizeUrls": true,
  "fuzzyField": "name",
  "fuzzyThreshold": 88,
  "fuzzyBlockFields": ["city"]
}
```

### Output example

The merged items, with your fields as they were (after keep, drop and rename):

```json
{ "url": "https://beta.pt", "name": "Beta, Lda", "city": "Porto", "price": 6, "rating": 4.5, "_sourceDatasetId": "XyZ987654321" }
```

And a `SUMMARY` record:

```json
{
  "status": "ok",
  "inputItems": 60000,
  "outputItems": 50000,
  "duplicatesRemoved": 10000,
  "fuzzyDuplicatesRemoved": 0,
  "filteredOut": 0,
  "perDataset": { "O68e8nGfTMr8gBp9M": { "read": 60000, "filteredOut": 0, "output": 50000 } },
  "durationSec": 41.2
}
```

### Pricing

Try it free: start a run with no dataset picked and the Actor dedupes a built-in sample of 5 items (3 come out). Nothing is charged for the sample apart from the small start fee.

Pay per event: a small fee per run, **$0.03 per 1,000 items written** to the output and **$0.002 per 1,000 items read**. Duplicates and filtered items only count as read. Example: 60,000 items in, 50,000 unique out costs about $1.62. Set a maximum cost per run in the run options for a hard cap.

### Limits

- `keepWhich` = `last` or `mostComplete` reads the input twice (to find the winner first, then write in the original order). `first` reads it once.
- Memory: about 100 bytes per unique key for `first`, about 250 bytes for `last` and `mostComplete`. 1 GB handles several million unique keys.
- Fuzzy matching compares each item with up to 5,000 earlier items in its block (same block fields and same first letters). Use blocking fields for big datasets; fuzzy works with `keepWhich` = `first`.
- Filters are simple field rules, not code; there is no JavaScript transform function.

### Questions and issues

Open an issue on the Actor page with the run ID.

# Actor input Schema

## `datasetIds` (type: `array`):

Empty: a free 5-item built-in sample runs, to show what the Actor does (nothing is charged). One or more datasets. Items are read in this order, page by page, so very large datasets work.

## `dedupe` (type: `boolean`):

Off: only merge (and filter or transform).

## `dedupFields` (type: `array`):

Two items with the same values in these fields are duplicates, for example url, or name and city. Nested fields use dots: address.city. Empty means the whole item must be identical.

## `keepWhich` (type: `string`):

first: the first one found (datasets in the order given). last: the newest one. mostComplete: the one with the most filled-in fields.

## `keepItemsWithEmptyKey` (type: `boolean`):

On: items with no value in all key fields are kept (they cannot be compared). Off: they are removed.

## `ignoreCase` (type: `boolean`):

ACME and acme count as the same.

## `ignoreAccents` (type: `boolean`):

Café and Cafe count as the same.

## `collapseWhitespace` (type: `boolean`):

Several spaces, tabs or line breaks count as one space.

## `normalizeUrls` (type: `boolean`):

http vs https, www., a trailing slash, #anchors and utm\_ tracking parameters are ignored.

## `digitsOnly` (type: `boolean`):

Keeps only digits before comparing. Useful for phone numbers: +351 912-345-678 equals 351912345678.

## `fuzzyField` (type: `string`):

Also removes near duplicates on this text field, for example company names Acme Inc and ACME Inc. Works with keepWhich = first.

## `fuzzyThreshold` (type: `integer`):

How similar two values must be to count as duplicates. 90 is strict, 80 is loose.

## `fuzzyBlockFields` (type: `array`):

Fields that must match exactly before two items are compared, for example city or country. Makes fuzzy matching faster and safer.

## `fuzzyPrefixLength` (type: `integer`):

Only values that start with the same N letters are compared (speed). 0 compares everything inside a block.

## `filters` (type: `array`):

Keep only items that match. Each filter: {"field": "price", "op": "gt", "value": 10}. Ops: eq, ne, contains, notContains, gt, gte, lt, lte, exists, notExists, regex, in. No code is run.

## `fieldsToKeep` (type: `array`):

If set, output items have only these fields. Nested fields with dots, for example address.city.

## `fieldsToDrop` (type: `array`):

Top-level fields removed from every item. Ignored when Keep only these fields is set.

## `renameMap` (type: `object`):

Old name to new name, for example {"title": "name"}.

## `addSourceDatasetId` (type: `boolean`):

Adds a field \_sourceDatasetId.

## `outputDatasetName` (type: `string`):

Optional. Results go to a named dataset (kept forever, reusable) instead of the run's default dataset.

## `appendToDatasetId` (type: `string`):

Optional. Results are added to this dataset.

## `limitPerDataset` (type: `integer`):

Empty means all.

## `maxOutputItems` (type: `integer`):

Stop after this many items are written. Empty means no limit.

## `pageSize` (type: `integer`):

Bigger is faster but uses more memory.

## Actor input object example

```json
{
  "dedupe": true,
  "dedupFields": [
    "url"
  ],
  "keepWhich": "first",
  "keepItemsWithEmptyKey": true,
  "ignoreCase": false,
  "ignoreAccents": false,
  "collapseWhitespace": false,
  "normalizeUrls": false,
  "digitsOnly": false,
  "fuzzyThreshold": 90,
  "fuzzyPrefixLength": 2,
  "addSourceDatasetId": false,
  "pageSize": 10000
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "dedupFields": [
        "url"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("solidactors/merge-dedupe-datasets").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "dedupFields": ["url"] }

# Run the Actor and wait for it to finish
run = client.actor("solidactors/merge-dedupe-datasets").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "dedupFields": [
    "url"
  ]
}' |
apify call solidactors/merge-dedupe-datasets --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,solidactors/merge-dedupe-datasets"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/EahfrLuR0pY0WmLiR/builds/sViggSQnWJ1ERCBIh/openapi.json
