Introduction to searching elasticsearch index documents

Source: Internet
Author: User
1. First, submit the following data to es to create an index.

{"Number": 32768, "Singer": "Yang Kun", "size": "5109132", "Song": "", "tag ": "Voice of China", "timelen": 319}
{"Number": 32769, "Singer": "Wang Feng", "size": "6001697", "Song": "I love you China", "tag ": "Voice of China", "timelen": 375}
{"Number": 32780, "Singer": "Wang Feng", "size": "4070469", "Song": "I love you so", "tag ": "Voice of China", "timelen": 254}
{"Number": 32796, "Singer": "", "size": "3046005", "Song": "", "tag": "Children's songs ", & quot; timelen & quot;: 190}
{"Number": 32896, "Singer": "Bandari", "size": "3869593", "Song": "The Golden Land", "tag ": "fetal music", "timelen": 241}
{"Number": 32977, "Singer": "Bandari", "size": "3477514", "Song": "childhood memory", "tag": "Europe and America ", & quot; timelen & quot;: 217}

2. elasticsearch's query DSL

The Restful API for search is

URL format: http: // ip: Port/index/type/_ search

The query statement is sent to es through post.

A. Basic full-text search

Search for records in the index library that contain "music"

{
"Query ":{
"QUERY_STRING ":{
"Query": "music"
}
}
}


B. Search by specified fields

Search for records containing China in the Song Field

{
"Query ":{
"QUERY_STRING ":{
"Query": "China ",
"Fields ":[
"Song"
]
}
}
}


C. Multi-field weight Query

Search for the keyword "China" in the song and tag fields. If the weight is 2 in the Song field, the default value is 1 in the tag field. The results show that the song name contains China, which is the top one.

{
"Query ":{
"Multi_match ":{
"Query": "China ",
"Fields ":[
"Song ^ 2 ",
"Tag"
]
}
}
}


For more detailed query syntax, see: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-queries.html

Introduction to searching elasticsearch index documents

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.