> ## 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.

# Query Stages API

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/4/fusion-server/reference/api/query/query-stages-api

[mintlify link]: https://doc.lucidworks.com/docs/4/fusion-server/reference/api/query/query-stages-api

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

The Query Stages API provides endpoints to:

* List query stage configuration properties
* Manage query stage instances
* Test processing on a set of queries

<LwTemplate />

## Examples

*See all defined query pipeline stages, regardless of type:*

**REQUEST**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD https://FUSION_HOST:8764/api/query-stages/instances
```

**RESPONSE**

```json wrap  theme={"dark"}
[{
  "type" : "query-logging",
  "id" : "detailed-logging",
  "detailed" : true,
  "skip" : false,
  "label" : "detailed-query-logging",
}]
```

*Add a new query stage:*

**REQUEST**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD -X POST -H 'Content-type: application/json' -d'{ "type" : "query-logging", "id" : "detailed-logging", "detailed" : true }' https://FUSION_HOST:8764/api/query-stages/instances
```

**RESPONSE**

```json wrap  theme={"dark"}
 {
  "type" : "query-logging",
  "id" : "detailed-logging",
  "detailed" : true,
  "skip" : false,
  "label" : "query-logging"
}
```

*Update a query stage:*

**REQUEST**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD -X PUT -H 'Content-type: application/json' -d'{ "type" : "query-logging", "id" : "detailed-logging", "detailed" : true, "label" : "detailed-query-logging" }' https://FUSION_HOST:8764/api/query-stages/instances/detailed-logging
```

**RESPONSE**

```json wrap  theme={"dark"}
{
  "type" : "query-logging",
  "id" : "detailed-logging",
  "detailed" : true,
  "skip" : false,
  "label" : "detailed-query-logging",
}
```

Note that all required elements must be included in the update.

*Delete a query stage:*

**REQUEST**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD -X DELETE https://FUSION_HOST:8764/api/query-stages/instances/detailed-logging
```

No response is returned. To check that the stage is no longer defined, list all query stage instances.

*Test that a set-params stage defines properties correctly:*

**REQUEST**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD -X POST -H 'Content-type: application/json' -d '{"type":"set-params", "params":[{"key":"rows", "value":"2", "policy":"append"}]}' https://FUSION_HOST:8764/api/query-stages/solr/test?q=*:*
```

**RESPONSE**

```json wrap  theme={"dark"}
{
  "request" : {
    "headers" : {
      "User-Agent" : [ "curl/7.30.0" ],
      "Content-Type" : [ "application/json" ],
      "Accept" : [ "*/*" ],
      "Host" : [ "fusion-host:{api-port}" ],
      "Content-Length" : [ "80" ]
    },
    "params" : {
      "q" : [ "*:*" ],
      "rows" : [ "2" ]
    }
  },
  "response" : null,
  "totalTime" : 0
}
```

*Get the properties for the "apply-defaults" type:*

**REQUEST**

```bash wrap  theme={"dark"}
curl -u USERNAME:PASSWORD https://FUSION_HOST:8764/api/query-stages/schema/set-params
```

**RESPONSE**

```json wrap  theme={"dark"}
{
  "type" : "object",
  "title" : "Additional Query Parameters",
  "description" : "This stage allows you to set, append, and remove additional query parameters",
  "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", "javascript", "advanced" ]
    },
    "params" : {
      "type" : "array",
      "title" : "Parameters and Values",
      "items" : {
        "type" : "object",
        "required" : [ "key" ],
        "properties" : {
          "key" : {
            "type" : "string",
            "title" : "Parameter Name"
          },
          "value" : {
            "type" : "string",
            "title" : "Parameter Value"
          },
          "policy" : {
            "type" : "string",
            "title" : "Update Policy",
            "enum" : [ "replace", "append", "remove", "default" ],
            "default" : "append"
          }
        }
      }
    }
  },
  "category" : "Advanced",
  "categoryPriority" : 2
}
```
