branch-4.0: [feature](search) Add multi-field search support with fields parameter #59845#60010
Merged
yiguolei merged 1 commit intobranch-4.0from Jan 19, 2026
Merged
Conversation
#59845) ### What problem does this PR solve? Issue Number: close #xxx Related PR: #59394 Problem Summary: This PR adds `fields` and `type` parameters to the SEARCH function, allowing queries to search across multiple fields with a single query term. This is similar to Elasticsearch's multi_match query with `best_fields` and `cross_fields` types. #### Multi-Field Search Support ```sql -- Single term across multiple fields (best_fields mode - default) SELECT * FROM docs WHERE search('hello', '{"fields":["title","content"]}'); -- Equivalent to: (title:hello) OR (content:hello) -- Multi-term with AND operator (best_fields mode - default) SELECT * FROM docs WHERE search('hello world', '{"fields":["title","content"],"default_operator":"and"}'); -- Equivalent to: (title:hello AND title:world) OR (content:hello AND content:world) -- Multi-term with cross_fields mode SELECT * FROM docs WHERE search('hello world', '{"fields":["title","content"],"default_operator":"and","type":"cross_fields"}'); -- Equivalent to: (title:hello OR content:hello) AND (title:world OR content:world) -- Combined with Lucene mode SELECT * FROM docs WHERE search('machine AND learning', '{"fields":["title","content"],"mode":"lucene","minimum_should_match":0}'); ``` #### Type Parameter Options | Type | Description | Behavior | |------|-------------|----------| | `best_fields` (default) | All terms must match within the **SAME** field | `"hello world"` → `(title:hello AND title:world) OR (content:hello AND content:world)` | | `cross_fields` | Terms can match across **DIFFERENT** fields | `"hello world"` → `(title:hello OR content:hello) AND (title:world OR content:world)` | **Key features:** - `type` parameter controls how terms are matched across fields - `best_fields` (default): Finds documents where all terms appear in the same field - ideal for relevance ranking - `cross_fields`: Treats multiple fields as one big field - ideal for name searches across first_name/last_name - Compatible with both standard mode and Lucene boolean mode - `fields` and `default_field` are mutually exclusive - Supports functions (EXACT, ANY, ALL) across fields - Supports wildcard queries across fields **Behavior examples:** | Query | Fields | Type | Expanded DSL | |-------|--------|------|--------------| | `hello` | `["title","content"]` | best_fields | `(title:hello) OR (content:hello)` | | `hello world` (AND) | `["title","content"]` | best_fields | `(title:hello AND title:world) OR (content:hello AND content:world)` | | `hello world` (AND) | `["title","content"]` | cross_fields | `(title:hello OR content:hello) AND (title:world OR content:world)` | | `EXACT(foo bar)` | `["title","content"]` | any | `(title:EXACT(foo bar) OR content:EXACT(foo bar))` | | `hello AND category:tech` | `["title","content"]` | any | `(title:hello OR content:hello) AND category:tech` | **Use case examples:** - **Product search**: Use `best_fields` when searching product name and description - prefer products where query terms appear together - **Person name search**: Use `cross_fields` when searching first_name and last_name - "John Smith" should match documents with `first_name:John` and `last_name:Smith` ### Release note - Add multi-field search support for SEARCH function (`fields` parameter) - Add `type` parameter with `best_fields` (default) and `cross_fields` modes - `best_fields`: All terms must match within the same field (default, matches Elasticsearch behavior) - `cross_fields`: Terms can match across different fields - Compatible with Lucene mode for MUST/SHOULD/MUST_NOT semantics
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
yiguolei
approved these changes
Jan 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-picked from #59845