Reducing Nested Clauses with Copy Fields

If you're hitting the 1,024 nested clause limit, you can reduce query complexity by consolidating multiple searchable fields into a single copy field. This guide shows you several strategies, with detailed steps for implementing the most effective solution.

Note: Before starting, you'll need your SearchStax Read/Write API token to modify your search schema. See Ingesting data with the Ingest API for instructions on finding your token.

Quick Reduction Strategies

Consider these options to reduce nested clauses in your queries:

  • Switch ngram fields to fulltext: If your users typically search with multi-word phrases, convert fulltext ngram fields back to regular fulltext. This reduces clauses from 15 per field to 6 per field.
  • Audit and remove redundant fields: Remove duplicate or low-value fields from your search field configuration. Each field you eliminate directly reduces clause count.
  • Use language-specific field sets: If you're indexing multiple languages, build logic to search only the fields for the user's current language instead of searching all language variants.
  • Consolidate with copy fields: Create a single merged field that combines content from multiple fields. This is the most effective solution for complex configurations.

The rest of this guide focuses on the copy field approach, which provides the greatest clause reduction.

How Copy Fields Work

A copy field automatically merges content from multiple source fields into a single destination field at index time. Instead of searching across many individual fields, you search the consolidated field.

Example scenario:

You currently search across these 5 fields:

  • title
  • description
  • author
  • category
  • keywords

Your current query looks like this:

q=title:hospital OR description:hospital OR author:hospital OR category:hospital OR keywords:hospital

With a copy field, you'll create a single _text_all_ field containing content from all five sources. Your new query becomes:

q=_text_all_:hospital

This reduces complexity while often improving relevance, since terms appearing across multiple fields naturally rank higher in the merged field.

Creating a Copy Field

You'll use the Schema API to create and configure your copy field. Since SearchStax uses a managed schema, all changes go through API calls rather than direct file editing.

Note: Replace <your_collection> with your actual deployment name and <your_endpoint> with your SearchStax API endpoint in the examples below.

Step 1: Create the Destination Field

First, create a new field to hold the consolidated content:

curl -X POST https://<your_endpoint>/solr/<your_collection>/schema/fields \
  -H 'Content-type:application/json' \
  -H 'Authorization: Bearer <your_token>' \
  -d '{
    "add-field": {
      "name": "_text_all_",
      "type": "text_general",
      "stored": false,
      "indexed": true,
      "multiValued": true
    }
  }'

Here's what each property does:

  • name: The field identifier. Using an underscore prefix (like _text_all_) is a convention for system-generated fields.
  • type: Use text_general for general-purpose text analysis with stemming and tokenization.
  • stored: Set to false because you don't need to retrieve this field's content—you're only searching it.
  • indexed: Set to true to make the field searchable.
  • multiValued: Set to true to allow copying from multiple source fields.

Step 2: Add Copy Field Rules

Next, configure which fields should copy their content into _text_all_:

curl -X POST https://<your_endpoint>/solr/<your_collection>/schema \
  -H 'Content-type:application/json' \
  -H 'Authorization: Bearer <your_token>' \
  -d '{
    "add-copy-field": [
      {"source": "title",       "dest": "_text_all_"},
      {"source": "description", "dest": "_text_all_"},
      {"source": "author",      "dest": "_text_all_"},
      {"source": "category",    "dest": "_text_all_"},
      {"source": "keywords",    "dest": "_text_all_"}
    ]
  }'

Add one entry for each field you want to consolidate. The copy happens automatically during indexing—no changes to your data pipeline are needed.

Step 3: Re-Index Your Data

Copy field rules only apply to documents indexed after the schema change. You'll need to re-index your existing content for the _text_all_ field to populate.

The re-indexing method depends on your data source:

  • Web crawler: Trigger a full crawl from your SearchStax dashboard
  • API ingestion: Re-run your indexing script or ETL pipeline
  • Database connector: Trigger a full sync from your connector configuration

Tip: You can verify the copy field is working by querying a few documents and checking that _text_all_ contains the expected merged content.

Step 4: Update Your Queries

Finally, modify your search application to query the new _text_all_ field instead of the individual fields:

Before:

q=title:hospital OR description:hospital OR author:hospital OR category:hospital OR keywords:hospital

After:

q=_text_all_:hospital

If you're using the SearchStax UI Kits or Hosted Search Experience, update your field configuration to reference _text_all_ as the primary search field.

Benefits of Copy Fields

Using copy fields provides several advantages beyond solving the nested clause limit:

  • Better performance: Fewer fields to search means faster query execution
  • Improved relevance: Terms appearing in multiple source fields score higher naturally in the merged field
  • Simpler queries: Easier to maintain and debug search configurations
  • Future-proof scaling: You can add more source fields without increasing query complexity

Troubleshooting

Copy Field Not Populating

If the _text_all_ field remains empty after re-indexing:

  • Verify the schema changes were applied using the Schema API's GET endpoint
  • Check that your source field names match exactly (case-sensitive)
  • Confirm you've re-indexed data after creating the copy field rules

Relevance Changes

If search results change unexpectedly after switching to a copy field:

  • The merged field treats all source content equally. If you previously boosted certain fields (like title), you'll need to recreate that boosting using query-time field weights or separate copy fields with different boost values.
  • Consider creating multiple copy fields with different configurations if you need fine-grained relevance control

Related Articles

Articles in this section