Elasticsearch: nested object under path is not of nested type

前端 未结 2 905
暗喜
暗喜 2020-12-15 03:54

I\'ve been trying to search on my document which contains a nested field. I created the nested mapping like this:

{
  \"message\": {
    \"properties\": {
          


        
相关标签:
2条回答
  • 2020-12-15 04:23

    TLDR: Put "type": "nested", in your nested type.

    Say we have a normal type, and another type nested in it:

    {
       "some_index": {
          "mappings": {
             "normal_type": {
                "properties": {
                   "nested_type": {
                      "type": "nested",
                      "properties": {
                         "address": {
                            "type": "string"
                         },
                         "country": {
                            "type": "string"
                         }
                      }
                   },
                   "first_name": {
                      "type": "string"
                   },
                   "last_name": {
                      "type": "string"
                   }
                }
             }
          }
       }
    }
    

    The "type": "nested", line is required for the nested queries to work which have "path": assigned to nested_type, like this:

    GET /some_index/normal_type/_search
    {
      "query": {
        "nested": {
          "query": {
            "bool": {}
          },
          "path": "nested_type"
        }
      }
    }
    

    The "type": "nested", line seems to be required in newer Elasticsearch versions only (since 1.1.1 ?).

    0 讨论(0)
  • 2020-12-15 04:25

    Syntax error in query DSL. Incorrect closing for must block query->bool->must

    {
        "query": {
            "bool": {
                    "must": [
    
                }// Should be ] 
            }
        }
    }
    

    Correct version query are :

    curl -XGET 'localhost:9200/thread_and_messages/thread/_search' -d '{
       "query": {
          "bool": {
             "must": [
                {
                   "match": {
                      "thread_name": "Banana"
                   }
                },
                {
                   "nested": {
                      "path": "messages",
                      "query": {
                         "bool": {
                            "must": [
                               {
                                  "match": {
                                     "messages.message_text": "Banana"
                                  }
                               }
                            ]
                         }
                      }
                   }
                }
             ]
          }
       }
    }'
    
    0 讨论(0)
提交回复
热议问题