Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best approch of Elastic Search time based feeds module?

I am new with elastic search and looking for the best solution with which i can create a feed module which have time based feeds along with there group and comment.

I learned little and come up with following.

PUT /group
    {
      "mappings": {
        "groupDetail": {},
        "content": {
          "_parent": {
            "type": "groupDetail" 
          }
        },
        "comment": {
          "_parent": {
            "type": "content" 
          }
        }
      }
    }

so that will be placed separately as per index.

but than after i found one post where i found that parent child is costly operation for search than nested objects.

something like following is two group(feed) having details with content and comments as nested element.

{
  "_index": "group",
  "_type": "groupDetail",
  "_id": 6829,
  "_score": 1,
  "_source": {
    "groupid": 6829,
    "name": "Jignesh Public",
    "insdate": "2016-10-01T04:09:33.916Z",
    "upddate": "2017-04-19T05:19:40.281Z",
    "isVerified": true,
    "tags": [
      "spotrs",
      "surat"
    ],
    "content": [
      {
        "contentid": 1,
        "type": "1",
        "byUser": 5858,
        "insdate": "2016-10-01 11:20",
        "info": [
          {
            "t": 1,
            "v": "lorem ipsum long text 1"
          },
          {
            "t": 2,
            "v": "http://www.imageurl.com/1"
          }
        ],
        "comments": [
          {
            "byuser": 5859,
            "comment": "Comment 1",
            "upddate": "2016-10-01T04:09:33.916Z"
          },
          {
            "byuser": 5860,
            "comment": "Comment 2",
            "upddate": "2016-10-01T04:09:33.916Z"
          }
        ]
      },
      {
        "contentid": 2,
        "type": "2",
        "byUser": 5859,
        "insdate": "2016-10-01 11:20",
        "info": [
          {
            "t": 4,
            "v": "http://www.videoURL.com/1"
          }
        ],
        "comments": [
          {
            "byuser": 5859,
            "comment": "Comment 1",
            "upddate": "2016-10-01T04:09:33.916Z"
          },
          {
            "byuser": 5860,
            "comment": "Comment 2",
            "upddate": "2016-10-01T04:09:33.916Z"
          }
        ]
      }
    ]
  }
}

{
  "_index": "group",
  "_type": "groupDetail",
  "_id": 6849,
  "_score": 1,
  "_source": {
    "groupid": 6849,
    "name": "Xyz Group Public",
    "insdate": "2016-10-01T04:09:33.916Z",
    "upddate": "2017-04-19T05:19:40.281Z",
    "isVerified": false,
    "tags": [
      "spotrs",
      "food"
    ],
    "content": [
      {
        "contentid": 3,
        "type": "1",
        "byUser": 5858,
        "insdate": "2016-10-01 11:20",
        "info": [
          {
            "t": 1,
            "v": "lorem ipsum long text 3"
          },
          {
            "t": 2,
            "v": "http://www.imageurl.com/1"
          }
        ],
        "comments": [
          {
            "byuser": 5859,
            "comment": "Comment 1",
            "upddate": "2016-10-01T04:09:33.916Z"
          },
          {
            "byuser": 5860,
            "comment": "Comment 2",
            "upddate": "2016-10-01T04:09:33.916Z"
          }
        ]
      },
      {
        "contentid": 4,
        "type": "2",
        "byUser": 5859,
        "insdate": "2016-10-01 11:20",
        "info": [
          {
            "t": 4,
            "v": "http://www.videoURL.com/1"
          }
        ],
        "comments": [
          {
            "byuser": 5859,
            "comment": "Comment 1",
            "upddate": "2016-10-01T04:09:33.916Z"
          },
          {
            "byuser": 5860,
            "comment": "Comment 2",
            "upddate": "2016-10-01T04:09:33.916Z"
          }
        ]
      }
    ]
  }
}

now if i try to think with nested object than i confused if user add comment very frequently than reindexing factor will effect?

So main think i want to ask is which is the best approach with which i can add comment frequently and my content searching result is also faster.

like image 205
Parth Patel p1nt0z Avatar asked Jul 12 '17 15:07

Parth Patel p1nt0z


2 Answers

Performance

  • Parent/child stores relevant data in same shards, as separately doc, which avoid the network;
  • Parent/child needs a joining process when retrieving data;
  • Nested object store the inner and outer object together, as a single doc;

So, we can infer:

  • Update nested object will re-index whole index, which can very expensive if your document is large;
  • Update parent or child alone will not affect the other one;
  • Searching nested object is a little fast, which save the process of joining;

Suggestions

As far as I understand your problem, you should use parent/child.

  • When your group's comments become more and more, adding a new comment will still re-index whole content, which can be very time-consuming;
  • On the other hand, search a comment with parent/child just need one more look up after finding the child, which is relative acceptable.

Furthermore, you should also take the rate of searching a comment comparing to adding a comment into account:

  • If you need searching a lot but a little new comments, maybe you can choose nested object;
  • Otherwise, choose parent/child;

By the way, you may combine both of them:

  • When this feed is active, use parent/child to store them;
  • When it is closed, i.e., no more comments can be added, move them to a new index with nested object;
like image 158
Tony Avatar answered Nov 04 '22 17:11

Tony


If you do not specify more detailed info other than very frequently it is going to be hard to come up with a recommendation. Also you have not mentioned how your data looks like. A comment in a blog post might be happening rare, even in heated discussions. A comment/reply in a forum post (that will result in a huge document) might be sth very different. I'd personally start with nested and see how it goes, but I also do not know all the requirements, so this might be a very wrong answer.

like image 2
alr Avatar answered Nov 04 '22 16:11

alr