Implementing many to many relations with elastic

Hi.
i have news, category and news_category_relation tables in mysql and i use logstash to import these data to elastic.
i want to get relational data of news and its categoies in one query that have output like below:

news {
"title" : "test",
"createdAt" : "45666677868",
"category" : {
{"id" : 1,
"title" : "news_category1"
},
{"id" : 2,
"title" : "news_category2"
}
}
}

my data for news and category and those relation store in separate indexes.
i tried parent/child approach but this approach use different type in one index and latest version of elastic does'nt support this feature.
please help me, how to do this?

The first thing you need to think about is the use case.

What people want to search for? News? Categories?

Let's say that they want to search for news. Then I'd index documents like:

{
  "title" : "test",
  "createdAt" : "45666677868",
  "category" : [
    { 
      "id" : 1,
      "title" : "news_category1"
    },
    { 
      "id" : 2,
      "title" : "news_category2"
    }
  ]
}

I'd even simplify more with:

{
  "title" : "test",
  "createdAt" : "45666677868",
  "category" : [ "news_category1", "news_category2" ]
}

But it depends on the use case.

1 Like

i want when choose a specific category showing all related news,
then i want filter and search categories.

What prevents doing so with the model I proposed?

you doing this with parent/child approach?
i don`t know how implement this with logstash statemenets, and kibana queries.

you doing this with parent/child approach?

No. It's not needed.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.