> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Property Index Stage

export const schema = {
  "type": "object",
  "title": "Set Property",
  "description": "A stage can conditionally set a value on a document or into the Pipeline Context for downstream consumption by having any one of the simple conditions return true. If you wish to have a more complex condition than the ones provided here, than use the Javascript Conditional option available on the stage.",
  "required": ["outputType"],
  "properties": {
    "skip": {
      "type": "boolean",
      "title": "Skip This Stage",
      "description": "Set to true to skip this stage.",
      "default": false,
      "hints": ["advanced"]
    },
    "label": {
      "type": "string",
      "title": "Label",
      "description": "A unique label for this stage.",
      "hints": ["advanced"],
      "maxLength": 255
    },
    "condition": {
      "type": "string",
      "title": "Condition",
      "description": "Define a conditional script that must result in true or false. This can be used to determine if the stage should process or not.",
      "hints": ["code", "code/javascript", "advanced"]
    },
    "source": {
      "type": "array",
      "title": "Source",
      "description": "The source fields and context keys to check conditions against.  If only the source fields are set and nothing else, then only set the property if all fields are present and non-null on the document.  May be a String Template.",
      "items": {
        "type": "string"
      }
    },
    "ifEquals": {
      "type": "string",
      "title": "If Value Equals",
      "description": "Check whether a value equals another value.  Valid entries for this are: another field/context key, the word 'null' or 'not null' (without the quotes) or a literal string (e.g. \"match\") in quotes (single or double).  The value may be a String Template."
    },
    "regularExpression": {
      "type": "string",
      "title": "Regular Expression Match",
      "description": "Apply the regular expression to the source fields and or context keys.  If any of them match, than set the property.  The implementation returns true if the regular expression matches anywhere in the string."
    },
    "outputKey": {
      "type": "string",
      "title": "Output Key",
      "description": "The name of the key to insert into the output location (document or context). May be a String Template. See https://github.com/antlr/stringtemplate4/blob/master/doc/index.md",
      "default": "setPropertyKey"
    },
    "outputValue": {
      "type": "string",
      "title": "Output Value",
      "description": "The value to set.  May be a String Template. See https://github.com/antlr/stringtemplate4/blob/master/doc/index.md",
      "default": "true"
    },
    "falseOutputValue": {
      "type": "string",
      "title": "False Output Value",
      "description": "The value to set when nothing matches.  If null/empty, then nothing will be output (same behavior as in Fusion 2.2).  May be a String Template. See https://github.com/antlr/stringtemplate4/blob/master/doc/index.md"
    },
    "whatMatchedKey": {
      "type": "string",
      "title": "What Matched Key",
      "description": "The name of the context key to use to store a space separated list of what conditionals matched.",
      "default": "whatMatched"
    },
    "outputType": {
      "type": "string",
      "title": "Output Type",
      "description": "Select whether the flag should be set on the document or in the Pipeline Context.",
      "enum": ["document", "context"],
      "default": "context"
    }
  },
  "category": "Advanced",
  "categoryPriority": 3,
  "unsafe": false
};

export const SchemaParamFields = ({schema}) => {
  const sanitize = str => {
    if (typeof str !== "string") return str;
    return str.replace(/^"(.*)"$/s, "$1").replace(/\\/g, "").replace(/"/g, "'");
  };
  const formatDescription = str => {
    const s = sanitize(str);
    return (/[.!?]\)*$/).test(s) ? s : `${s}.`;
  };
  const {description, properties = {}, required: requiredProps = []} = schema;
  const visibleProps = useMemo(() => Object.entries(properties).filter(([, prop]) => !prop.hints?.includes("hidden")), [properties]);
  return <div>
      {description && <p>{formatDescription(description)}</p>}

      {visibleProps.map(([name, prop]) => {
    const isRequired = requiredProps.includes(name);
    const hasDefault = prop.default !== undefined;
    const rawDefault = prop.default;
    const isComplexDefault = hasDefault && (typeof rawDefault === "object" || typeof rawDefault === "string" && (rawDefault.length > 20 || rawDefault.includes('"')));
    const fieldProps = {
      key: name,
      body: prop.title || name,
      type: prop.type,
      ...prop.title && ({
        post: [<><span className="text-stone-400 dark:text-stone-500">API property: </span>{name}</>]
      }),
      ...isRequired && ({
        required: true
      }),
      ...!isComplexDefault && hasDefault ? {
        default: sanitize(String(rawDefault))
      } : {}
    };
    const isObject = prop.type === "object" && prop.properties;
    const isArrayOfObjects = prop.type === "array" && prop.items?.type === "object" && prop.items.properties;
    return <ParamField {...fieldProps}>
            {prop.description && <p>{formatDescription(prop.description)}</p>}

            {isComplexDefault && <div className="flex">
                <p>
                  <strong>Default:</strong>
                </p>
                <pre className="!my-0">
                  <code>
                    {JSON.stringify(rawDefault, null, 2)}
                  </code>
                </pre>
              </div>}

            {isArrayOfObjects && <div className="flex">
              <p>
                <strong>Object attributes:</strong>
              </p>
              <pre className="!my-0">
                <code>
                  {'{\n'}
                  {Object.entries(prop.items.properties).map(([iname, iprop]) => <>
                      {`  ${iname}`}
                      {prop.items?.required?.includes(iname) && <span style={{
      color: 'red'
    }}> required</span>}
                      {`: {\n    display name: ${sanitize(iprop.title || '')}\n    type: ${iprop.type}\n  }\n`}
                    </>)}
                  {'}'}
                </code>
              </pre>
              </div>}

            {isObject && <Expandable title="properties">
                <SchemaParamFields schema={{
      properties: prop.properties,
      required: prop.required
    }} />
              </Expandable>}
          </ParamField>;
  })}
    </div>;
};

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/5/fusion/reference/config-ref/pipeline-stages/index-stages/set-property-index-stage

[mintlify link]: https://doc.lucidworks.com/docs/5/fusion/reference/config-ref/pipeline-stages/index-stages/set-property-index-stage

[old doc.lw link]: https://doc.lucidworks.com/fusion/5.9/239

The Set Property Index Stage is used to set a value on a document, or into the Pipeline Context for downstream consumption
by specifying a series of simple matching conditions.
These conditions match against whether a field exists, and simple substring matches on the field contents.
For more complex logic, use a [JavaScript Index Stage](/docs/5/fusion/reference/config-ref/pipeline-stages/index-stages/javascript-index-stage).

<LwTemplate />

## Configuration

<Tip>
  When entering configuration values in the UI, use *unescaped* characters, such as `\t` for the tab character. When entering configuration values in the API, use *escaped* characters, such as `\\t` for the tab character.
</Tip>

<SchemaParamFields schema={schema} />
