Use of the basic query API for ES

Source: Internet
Author: User
Tags parse error

This article mainly records the use of the basic query API for ESBasic query Type term query
{"     query": {"term        ": {            "title": "Crime"}}    }
    • Assigning weights

{"Query": {"term": {"            title": {                "value": "Crime",                "Boost": 10.0             }    }}
    • Multi-term query query tags contain novel or book

{"     query": {"        terms": {"            tags": ["Novel", "book"]    }}
Common Word Query

Simple understanding is to remove the high privilege of the stop word, divided into two groups to query, such as stop word is high frequency, Cutoff_frequency said that the word below this probability will appear in the low-frequency group.

{"Query": {"common": {"title": {"                 Query": "Crime and Punishment",                 "cutoff_frequency": 0.001             }        }    }}
Match query (Lucene query syntax not supported) query title contains crime or and or punishment documents
{"     query": {"        match": {            "title": "Crime and Punishment"}}    }
operator operator

Word breaker that requires and or or matches text

{"Query": {"match": {"title": {"                 Query": "Crime and Punishment", "                 Operator": "and"            }        }    }}
Phrase Query
{"Query": {"match_phrase": {"title": {"                 Query": "Crime  punishment",                 "slop": 1            }        }    }}
Prefix query

Prefix the last entry of the query keyword

{"Query": {"Match_phrase_prefix": {"title": {"                 Query": "Crime  Punish",                 "slop": 1,                 "max_expansions": +}}}    
Multi_match (query for multiple fields)
{"     query": {"        Multi_match": {"             query": "Crime  Heller",             "Fields": ["title", "author"]        }    }}
Query_string query (supports Lucene query syntax)

The title field contains crime and has a weight of 10, including punishment, but Otitle does not contain a cat, and the colleague author field contains Fyodor and Dostoevsky.

{"     query": {"        query_string": {             "query": "Title:crime^10 +title:punishment-otitle:cat +author: (+fyodor + Dostoevsky) ",             " Default_field ":" title "}}    
Querying for multiple fields

Use_dis_max using the maximum score, max means that for a given keyword, only the highest score is included in the score of the final document, not all of the field scores that contain the entry.

{"     query": {"        query_string": {"             query": "Crime Heller",             "Fields": ["title", "Author"],              "Use_dis _max ": True        }}    }
simple_query_string Query

Parse error without throwing exception, discard query invalid part

{"     query": {"        simple_query_string": {             "query": "Title:crime^10 +title:punishment-otitle:cat +author :(+fyodor +dostoevsky) ",             " Default_operator ":" or "        }    }
Identifier Query

Find using a unique representation of the UID

{"     query": {"        IDs": {"             type": "Book",             "values": ["1", "2", "3"]    }}}
Prefix query

Prefix matches a given keyword

{"     query": {"        prefix": {             "title": "Cri"        }}    }
    • Assigning weights

{"     query": {"prefix": {"             title": {                 "value": "CRI",                 "Boost": 3.0             }    }}
Fuzzy query

Fuzzy queries using editing distances are computationally significant, but are useful for user-misspelled scenarios

{"     query": {"        fuzzy": {             "title": "Crme"}}    }
    • Specify minimum similarity deviation

{"Query": {"fuzzy": {"title": {"                 value": "Crme",                 "min_similarity": 1    }}}
Wildcard Query

Support for * and? et wildcard characters

{"     query": {"        wildcard": {             "title": "Cr?me"}}    }
Scope Query

Can be for a single field only, numeric, or string-based.

{"Query": {"range": {"Year": {                  "GTE": 1890,                  "LTE": 1900              }    }}
Regular expression Query

Query performance depends on regular expression

{"     query": {"regexp": {"             title": {                  "value": "Cr.m[ae]",                  "Boost": 10.0              }    }}
Boolean query (combined query)
{"Query": {"bool": {"must": {"term                ": {                    "title": "Crime"                }            },             "should": {                ' Range ': {                    ' year ': {' from ': 1900, ' to ': ' + '}}            ,             ' Must_not '                : {' term ': {                    "Otitle": "Nothing"                }            }        }    }

Use of the basic query API for ES

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.