Craticula

Substring matching on OpenSearch

On OpenSearch and Elasticsearch, contains and not contains look for the text inside the value, exactly as a SQL substring match does. There is no tokenising, stemming or relevance scoring. A field can opt in to full-text matching explicitly if a host wants that instead.

Rule. On OpenSearch/Elasticsearch, contains/notContains ($defs/binaryOperator) compile to substring-matching query types — wildcard against a keyword field, or a per-field ngram- analyzed sub-field strategy (schema-configured) — never to a tokenized match query. This pins contains's behavior to exactly what SQL's LIKE '%pattern%' does: substring presence, no tokenization, no stemming, no stopword removal, no relevance scoring. A per-field, explicit opt-in searchMode: analyzed is the documented escape hatch for a host that deliberately wants relevance-style full-text matching instead of substring semantics for that field.

Rationale. ES/OpenSearch's idiomatic "search for text" mechanism is match against an analyzed field, and a naive compiler reaches for it because the operator is literally named contains and match reads as "does it contain this". That is the tokenized-match trap: match splits both the indexed field and the query string into analyzer tokens (lowercased, stemmed, stopword-filtered) and matches when any token overlaps — it does not check for a literal substring. contains: "art" against the indexed value "Smart Watch" returns no hit under match (the analyzer produces whole tokens "smart" and "watch", neither of which is "art"), while the identical filter compiled to SQL (LIKE '%art%') or Mongo ($regex) matches that row. The same IR silently diverges across backends — precisely the parity failure G3 exists to prevent, and the TRD's problem statement (§1) calls out ES/OpenSearch support as the one thing "nothing exists" for in any prior art, largely because this exact trap is unsolved elsewhere. Pinning substring semantics trades away ES's own relevance ranking for contains; searchMode: analyzed exists so a host can make that trade deliberately, per field, instead of getting it by accident.

Worked example — contains: "art" against name, where a document has name = "Smart Watch":

Must NOT.

Cross-links. $defs/binaryOperator (contains, notContains), $defs/stringValue (the value being substring-matched), $defs/fieldName.