1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can I update Elastic Search index

Discussion in 'XenForo Development Discussions' started by AndyB, Apr 3, 2014.

  1. AndyB

    AndyB Well-Known Member

    In my add-on Change Author, I have a requirement to update the Elastic Search index. The add-on changes the author of a post. The only step I'm missing at this point is to update Elastic Search.

    I would like to use this code with the appropriate code added:

    // check if ElasticSearch is enabled
    if (XenForo_Application::get('options')->enableElasticsearch)

    // add code here to update ElasticSearch index
    I would need Elastic Search to be updated as if I were to enter a new post or edit an existing one.

    Thank you.
  2. AndyB

    AndyB Well-Known Member

    Got it.

    // check if ElasticSearch is enabled
    if (XenForo_Application::get('options')->enableElasticsearch)
    // run query
    $data $db->fetchRow("
        SELECT xf_thread.node_id, 
        FROM xf_post
        INNER JOIN xf_thread ON xf_thread.thread_id = xf_post.thread_id 
        WHERE xf_post.post_id = ?
    // get ElasticSearch index name
    $indexName XenES_Api::getInstance()->getIndex();        
    // define variables
    $contentType 'post';
    $contentId $postId;
    // define record data
    $record = array(
    'node' => $data['node_id'],
    'thread' => $data['thread_id'],
    'title' => $data['title'], 
    'message' => $data['message'],
    'date' => $data['post_date'],
    'user' => $data['user_id'],
    'discussion_id' => $postId

    // update Elastic Search index
    Ketola and MattW like this.

Share This Page