Elasticsearch with multiple parent/child relationship

前端 未结 3 1435
轻奢々
轻奢々 2021-01-12 04:18

I\'m building an application with complicated model, says Book, User and Review.

A Review contains both Book and User id. To be able to search for Books that contai

3条回答
  •  盖世英雄少女心
    2021-01-12 04:57

    Somths like (just make Books type as parent for Users and Reviews types)

    .../index/users/_search?pretty" -d '
        {
            "query": {
                "filtered": {
                    "filter": {
                        "and": [
                            {
                                "has_parent": {
                                    "parent_type": "books",
                                    "filter": {
                                        "has_child": {
                                            "type": "Reviews",
                                            "query": {
                                                "term": {
                                                    "text_review": "some word"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        }
        '
    

提交回复
热议问题