Elasticsearch Learning problem record--nested query not data

Source: Internet
Author: User

Created by code with the index name Demoindex, the index type is school, the following is the data map structure of the index type:

{"state": "Open", "settings": {"Index.number_of_replicas": "1", "Index.number_of_shards": "5",  "index.version.created": "901399", "Index.uuid": "-z5eg5nnsp-vsnfuzamn-a"}, "mappings": {"School": {"Properties": {"id": {"store": True, "analyzer": "IK"                    , "type": "String"}, "name": {"store": true,                    "Analyzer": "Ik", "type": "String"}, "age": {                    "Store": true, "type": "Integer"}, "Studentlist": { "Properties": {"sex": {"store": true, "  Analyzer ":" Ik "," type ":" String "}," StudentID ":                      {      "Store": True, "analyzer": "Ik", "type": "String"                            }, "Studentname": {"store": true,                    "Analyzer": "Ik", "type": "String"}, "Type": "nested"}}}," aliases ": []}

There are nested relationships in the data structure, and the school attributes contain nested attributes Studentlist, which holds the students in the school. Here are all the data in Demoindex:

Use head for the following query, the results found that the results are not available. Here I have checked "show query statement".

Unable to find the answer had to resort to "Elasticsearch server development." After reviewing the nested types of nested queries need to use a dedicated search format. First post the original book Description:

{"Cloth": {"Properties": {"name": {"type": "string", "index": "Analyzed"}, "variation": {"type": "Nested", "Propertie S ": {" size ": {" type ":" string "," index ":" Not_analyzed "}," color ": {" type ":" string "," index ":" Not_analyzed "}}}} can be To see, we introduced the new object variation in the cloth type, which is nested (the Type property is set to nested), which indicates that you want to index the nested document. Now modify the document to add a variation object with two properties: size and color. The sample product will look like this: {"name": "Test Shirt", "variation": [{"Size": "XXL", "Color": "Red"},{"size": "XL", "Color": "Black"}]} Organize the document structure so that each dimension and its matching color become a separate document. However, if the previous query is executed, no documents will be returned. This is because, for nested files, you need to use a specialized query. Therefore, the query is as follows (of course, we have created the index and the type again): Curl-xget ' localhost:9200/shop/cloth/_search?pretty=true '-d ' {"Query": {"nested": {" Path ":" Variation "," query ": {" bool ": {" must ": [{" term ": {" variation.size ":" XXL "}},{" term ": {" Variation.color ":" Black "}"} "}}} ' Now, the above query will not be able to return the document in the index because a nested document with an XXL size and black color cannot be found. Here is a brief discussion of our query, and we can see that we use nested queries to query nested documents. The Path property specifies the name of the nested object (multiple names can be used). The nested type includes a standard query section. It should be noted that specifying the full path to the field name in the nested object is convenient (and possible) in the multilevel nesting.

The following query is described in the book, using the complex query method of head. Success, the data appeared!

Elasticsearch Learning problem record--nested query not data

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.