This topic explains how to target contexts in rule-based and smaller list-based segments. Smaller list-based segments are segments where the number of individual contexts targeted is 15,000 or fewer.
You can use custom targeting rules in a segment to include targets that match specific rules. Segment targeting rules function the same way as flag targeting rules. To learn more, read Target with flags.
To customize a segment’s targeting rules:

To reference this rule when working with other members of your organization, click the three-dot overflow menu and choose Copy link to rule.
To remove a targeting rule from a segment, click Edit. Then click the overflow menu and select “Delete rule.”
When you specify rules for a segment, LaunchDarkly parses them in order of appearance from top to bottom. You can change how segment targeting applies based on the order of the rules you create.
After you add targeting rules, you can also add individual contexts. To learn how, read Target individual contexts, below.
Each segment can include up to 5,000 targeting rules and 50,000 values across all rules.
If you target only a percentage of contexts that match your segment targeting rule, each flag that targets that segment will include the same contexts in its targeting, assuming there are no other differences between the flags’ targeting rules.
For example, imagine you configure a segment to target 50% of user contexts that match its rule:

As a result, the segment:
A, B, and CD, E, and FIf there are no other differences between the flags’ targeting rules, every flag that targets that segment will include user contexts A, B, and C in its targeting, and will exclude user contexts D, E, and F.
There are some differences between flag targeting and segment targeting:
Like flags, you cannot create a circular reference between two segments, for example, where segment A targets segment B and segment B targets segment A.
You can individually target contexts for inclusion in or exclusion from a segment. You can also edit individually targeted contexts in bulk, and schedule the removal of individually targeted contexts from a segment.
To individually target a context:
Navigate to the details page of the segment you wish to modify.
Click the + Add rule button and select “Include individuals” or “Exclude individuals.”
Choose the context kind for the contexts you want to target.

The “Included targets” or “Excluded targets” section updates to display the context kinds you selected.
Choose contexts to include in or exclude from the segment.
Click Save changes or, if your environment requires approvals, click Request approval. The contexts are now individually targeted within the segment.
Here is an image of an individually targeted context:

To remove all included or excluded contexts from a segment, click Edit in the header of the “Included targets” or “Excluded targets” section. Then, click the overflow menu and select “Clear.”

After you add contexts to a list-based segment, you can also add rules. To learn how, read Target contexts with rules, above.
If you have a long list of contexts you want to add, remove, or replace within a segment, you can bulk edit contexts from a segment’s details page. You can only perform bulk editing tasks for one context kind at a time.
To edit individual targets in bulk:

You can update the list on the right before you perform the selected action. The options for updating the list include the following:
context-key-123abc, and context-key-123abc already exists in LaunchDarkly, it will show up in this list.sandy@example.com, but there are multiple context keys that have sandy@example.com as an email address, the system may return multiple matching records. You can select the correct record by clicking the checkbox.Scheduling removal dates is only available to customers on select plans. To learn more, read about our pricing. To upgrade your plan, contact Sales.
You can schedule an expiration date and time on which LaunchDarkly removes a context from a segment. You can do this for existing contexts, or when you add a context to a segment.
This is useful if you want to give contexts temporary access to a feature that has their segment targeted. The ability to remove contexts from segments, instead of flag targeting, allows you to keep your flag’s targeting rules permanent and clean.
To set a targeting removal date:

Additionally, when you add a context to a segment, you can schedule it for removal later by clicking Add and schedule removal.
Here is an image of the targeting field:

You can also use the REST API: Update expiring targets for segment
Targeting contexts in rule-based and smaller list-based segments