Term query | Elasticsearch Guide [8.15] (2024)

« Regexp queryTerms query »

Elastic DocsElasticsearch Guide [8.15]Query DSLTerm-level queries

Term query

edit

Returns documents that contain an exact term in a provided field.

You can use the term query to find documents based on a precise value such asa price, a product ID, or a username.

Avoid using the term query for text fields.

By default, Elasticsearch changes the values of text fields as part of analysis. This can make finding exact matches for text field valuesdifficult.

To search text field values, use the match queryinstead.

resp = client.search( query={ "term": { "user.id": { "value": "kimchy", "boost": 1 } } },)print(resp)
response = client.search( body: { query: { term: { 'user.id' => { value: 'kimchy', boost: 1 } } } })puts response
const response = await client.search({ query: { term: { "user.id": { value: "kimchy", boost: 1, }, }, },});console.log(response);
GET /_search{ "query": { "term": { "user.id": { "value": "kimchy", "boost": 1.0 } } }}

Top-level parameters for term

edit

<field>
(Required, object) Field you wish to search.

Parameters for <field>

edit

value
(Required, string) Term you wish to find in the provided <field>. To return adocument, the term must exactly match the field value, including whitespace andcapitalization.
boost

(Optional, float) Floating point number used to decrease or increase therelevance scores of a query. Defaults to 1.0.

You can use the boost parameter to adjust relevance scores for searchescontaining two or more queries.

Boost values are relative to the default value of 1.0. A boost value between0 and 1.0 decreases the relevance score. A value greater than 1.0increases the relevance score.

case_insensitive [7.10.0]Added in 7.10.0.
(Optional, Boolean) Allows ASCII case insensitive matching of thevalue with the indexed field values when set to true. Default is false which meansthe case sensitivity of matching depends on the underlying field’s mapping.

Avoid using the term query for text fields

edit

By default, Elasticsearch changes the values of text fields during analysis. Forexample, the default standard analyzer changestext field values as follows:

  • Removes most punctuation
  • Divides the remaining content into individual words, calledtokens
  • Lowercases the tokens

To better search text fields, the match query also analyzes your providedsearch term before performing a search. This means the match query can searchtext fields for analyzed tokens rather than an exact term.

The term query does not analyze the search term. The term query onlysearches for the exact term you provide. This means the term query mayreturn poor or no results when searching text fields.

To see the difference in search results, try the following example.

  1. Create an index with a text field called full_text.

    resp = client.indices.create( index="my-index-000001", mappings={ "properties": { "full_text": { "type": "text" } } },)print(resp)
    response = client.indices.create( index: 'my-index-000001', body: { mappings: { properties: { full_text: { type: 'text' } } } })puts response
    res, err := es.Indices.Create("my-index-000001",es.Indices.Create.WithBody(strings.NewReader(`{ "mappings": { "properties": { "full_text": { "type": "text" } } }}`)),)fmt.Println(res, err)
    const response = await client.indices.create({ index: "my-index-000001", mappings: { properties: { full_text: { type: "text", }, }, },});console.log(response);
    PUT my-index-000001{ "mappings": { "properties": { "full_text": { "type": "text" } } }}
  2. Index a document with a value of Quick Brown Foxes! in the full_textfield.

    resp = client.index( index="my-index-000001", id="1", document={ "full_text": "Quick Brown Foxes!" },)print(resp)
    response = client.index( index: 'my-index-000001', id: 1, body: { full_text: 'Quick Brown Foxes!' })puts response
    res, err := es.Index("my-index-000001",strings.NewReader(`{ "full_text": "Quick Brown Foxes!"}`),es.Index.WithDocumentID("1"),es.Index.WithPretty(),)fmt.Println(res, err)
    const response = await client.index({ index: "my-index-000001", id: 1, document: { full_text: "Quick Brown Foxes!", },});console.log(response);
    PUT my-index-000001/_doc/1{ "full_text": "Quick Brown Foxes!"}

    Because full_text is a text field, Elasticsearch changes Quick Brown Foxes! to[quick, brown, fox] during analysis.

  3. Use the term query to search for Quick Brown Foxes! in the full_textfield. Include the pretty parameter so the response is more readable.

    resp = client.search( index="my-index-000001", pretty=True, query={ "term": { "full_text": "Quick Brown Foxes!" } },)print(resp)
    response = client.search( index: 'my-index-000001', pretty: true, body: { query: { term: { full_text: 'Quick Brown Foxes!' } } })puts response
    res, err := es.Search(es.Search.WithIndex("my-index-000001"),es.Search.WithBody(strings.NewReader(`{ "query": { "term": { "full_text": "Quick Brown Foxes!" } }}`)),es.Search.WithPretty(),)fmt.Println(res, err)
    const response = await client.search({ index: "my-index-000001", pretty: "true", query: { term: { full_text: "Quick Brown Foxes!", }, },});console.log(response);
    GET my-index-000001/_search?pretty{ "query": { "term": { "full_text": "Quick Brown Foxes!" } }}

    Because the full_text field no longer contains the exact term Quick BrownFoxes!, the term query search returns no results.

  4. Use the match query to search for Quick Brown Foxes! in the full_textfield.

    resp = client.search( index="my-index-000001", pretty=True, query={ "match": { "full_text": "Quick Brown Foxes!" } },)print(resp)
    response = client.search( index: 'my-index-000001', pretty: true, body: { query: { match: { full_text: 'Quick Brown Foxes!' } } })puts response
    res, err := es.Search(es.Search.WithIndex("my-index-000001"),es.Search.WithBody(strings.NewReader(`{ "query": { "match": { "full_text": "Quick Brown Foxes!" } }}`)),es.Search.WithPretty(),)fmt.Println(res, err)
    const response = await client.search({ index: "my-index-000001", pretty: "true", query: { match: { full_text: "Quick Brown Foxes!", }, },});console.log(response);
    GET my-index-000001/_search?pretty{ "query": { "match": { "full_text": "Quick Brown Foxes!" } }}

    Unlike the term query, the match query analyzes your provided search term,Quick Brown Foxes!, before performing a search. The match query then returnsany documents containing the quick, brown, or fox tokens in thefull_text field.

    Here’s the response for the match query search containing the indexed documentin the results.

    { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 0.8630463, "hits" : [ { "_index" : "my-index-000001", "_id" : "1", "_score" : 0.8630463, "_source" : { "full_text" : "Quick Brown Foxes!" } } ] }}

« Regexp queryTerms query »

Most Popular

Video

Get Started with Elasticsearch

Video

Intro to Kibana

Video

Term query | Elasticsearch Guide [8.15] (2024)
Top Articles
What It Means To Put A White Pumpkin On Your Porch - House Digest
Frequently Asked Questions on Soap
UPS Paketshop: Filialen & Standorte
Amc Near My Location
Was ist ein Crawler? | Finde es jetzt raus! | OMT-Lexikon
Kostenlose Games: Die besten Free to play Spiele 2024 - Update mit einem legendären Shooter
Tugboat Information
Natureza e Qualidade de Produtos - Gestão da Qualidade
Newgate Honda
2015 Honda Fit EX-L for sale - Seattle, WA - craigslist
Uc Santa Cruz Events
Chastity Brainwash
Blackwolf Run Pro Shop
Google Flights Missoula
DBZ Dokkan Battle Full-Power Tier List [All Cards Ranked]
2020 Military Pay Charts – Officer & Enlisted Pay Scales (3.1% Raise)
Army Oubs
Earl David Worden Military Service
Aldi Bruce B Downs
Atdhe Net
Air Quality Index Endicott Ny
Aol News Weather Entertainment Local Lifestyle
Gas Buddy Prices Near Me Zip Code
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
As families searched, a Texas medical school cut up their loved ones
4.231 Rounded To The Nearest Hundred
Riverstock Apartments Photos
What is Software Defined Networking (SDN)? - GeeksforGeeks
Memberweb Bw
2024 Coachella Predictions
Unity Webgl Player Drift Hunters
Craigslist Georgia Homes For Sale By Owner
Sams La Habra Gas Price
Directions To Advance Auto
Why I’m Joining Flipboard
Beaufort SC Mugshots
Mbfs Com Login
Dragon Ball Super Super Hero 123Movies
Booknet.com Contract Marriage 2
Royals Yankees Score
Cleveland Save 25% - Lighthouse Immersive Studios | Buy Tickets
St Vrain Schoology
Pixel Gun 3D Unblocked Games
Value Village Silver Spring Photos
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
Image Mate Orange County
M Life Insider
Edt National Board
Congressional hopeful Aisha Mills sees district as an economical model
Jovan Pulitzer Telegram
Dinargurus
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 6418

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.