Problems creating parent-child relationships in ElasticSearch 6

I'm currently working on an ElasticSearch Udemy course, but the video talks about ElasticSearch 5, and I'm currently using ElasticSearch 6. I am having trouble translating parent / child relationships into a new format.

The video is set Franchiseto Films(i.e., Star Warsand The Jedi Returnsaccordingly.

The mentor does the following:

curl -H "Content-Type: application/json" -XPUT "127.0.0.1:9200/series" -d '
{
    "mappings": {
        "franchise": {},
        "film": {
            "_parent": {
                "type": "franchise"
            }
        }
    }
}'

However, when I try to add mappings, I get the following errors:

➜  Downloads curl -H "Content-Type: application/json" -XPUT "127.0.0.1:9200/series?pretty" -d '
{
    "mappings": {
        "franchise": {},
        "film": {
            "_parent": {
                "type": "franchise"
            }
        }
    }
}'
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Rejecting mapping update to [series] as the final mapping would have more than 1 type: [franchise, film]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "Rejecting mapping update to [series] as the final mapping would have more than 1 type: [franchise, film]"
  },
  "status" : 400
}

, , soluton: https://www.elastic.co/blog/index-type-parent-child-join-now-future-in-elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/master/parent-join.html https://github.com/elastic/elasticsearch/issues/20257

TL;DR: - - ElastiSearch 5 ElasticSearch 6?


(): , , , :

JSON:

wget http://media.sundog-soft.com/es/series.json

JSON:

{ "create" : { "_index" : "series", "_type" : "franchise", "_id" : "1"} }
{ "id": "1", "title" : "Star Wars" }
{ "create" : { "_index" : "series", "_type" : "film", "_id" : "260", "parent" : "1" } }
{ "id": "260", "title" : "Star Wars: Episode IV - A New Hope", "year":"1977" , "genre":["Action", "Adventure", "Sci-Fi"] }

:

➜  curl -H "Content-Type: application/json" -XPUT "127.0.0.1:9200/_bulk?pretty" --data-binary @series.json
+4
2

Elasticsearch 6.0 , .

  • . .
  • / , , , _parent . /.

/ , . , , , 5.x .

, , / . Elasticsearch . . , , "1 " ( , , ), .

EDIT:

, Elasticsearch 6.x join field, .

, .

curl -XDELETE "http://localhost:9200/series"

, :

curl -XPUT "http://localhost:9200/series" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "doc": {
      "properties": {
        "join_field": { 
          "type": "join",
          "relations": {
            "franchise": "film" 
          }
        }
      }
    }
  }
}'

series.json :

curl -XPOST "http://localhost:9200/_bulk" -H 'Content-Type: application/json' -d'
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1"} }
{ "id": "1", "title" : "Star Wars", "join_field": "franchise" }
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "260", "routing" : "1" } }
{ "id": "260", "title" : "Star Wars: Episode IV - A New Hope", "year":"1977" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1196", "routing" : "1" } }
{ "id": "1196", "title" : "Star Wars: Episode V - The Empire Strikes Back", "year":"1980" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1210", "routing" : "1" } }
{ "id": "1210", "title" : "Star Wars: Episode VI - Return of the Jedi", "year":"1983" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "2628", "routing" : "1" } }
{ "id": "2628", "title" : "Star Wars: Episode I - The Phantom Menace", "year":"1999" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "5378", "routing" : "1" } }
{ "id": "5378", "title" : "Star Wars: Episode II - Attack of the Clones", "year":"2002" , "genre":["Action", "Adventure", "Sci-Fi", "IMAX"], "join_field": {"name": "film", "parent": "1"} }
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "33493", "routing" : "1" } }
{ "id": "33493", "title" : "Star Wars: Episode III - Revenge of the Sith", "year":"2005" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "122886", "routing" : "1" } }
{ "id": "122886", "title" : "Star Wars: Episode VII - The Force Awakens", "year":"2015" , "genre":["Action", "Adventure", "Fantasy", "Sci-Fi", "IMAX"], "join_field": {"name": "film", "parent": "1"} }
'

, .

id = 1, .

curl -XGET "http://localhost:9200/series/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "parent_id": { 
      "type": "film",
      "id": "1"
    }
  }
}'
+6

, @Pranav Shukla , , (, "The Force Awakens" ), :

curl -XGET localhost:9200/series/_search?pretty -H 'Content-Type: application/json' -d '    
{                                          
  "query": {
    "has_child" : {
      "type": "film",
      "query": {
        "match": {
          "title": "The Force Awakens"
        }
      }
    }
  }
}'
+1

Source: https://habr.com/ru/post/1690432/


All Articles