Example #1
0
// Index indexes a contact into elasticsearch
func index(Contact *models.Contact, s *elastic.Client) error {
	id := strconv.Itoa(int(Contact.ID))
	if id == "" {
		logs.Error("id is nil")
		return errors.New("id is nil")
	}

	if Contact.Address.Longitude == "null" || Contact.Address.Latitude == "null" {
		logs.Debug("Could not index contact %s", id)
		return nil
	}

	if Contact.Address.Latitude != "" && Contact.Address.Longitude != "" {
		Contact.Address.Location = fmt.Sprintf("%s,%s", Contact.Address.Latitude, Contact.Address.Longitude)
	}

	_, err := s.Index().
		Index("contacts").
		Type("contact").
		Id(id).
		BodyJson(Contact).
		Do()
	if err != nil {
		logs.Critical(err)
		return err
	}

	logs.Debug("Contact %s indexed", id)

	return nil
}
Example #2
0
func indexFact(Fact models.Fact, client *elastic.Client) error {
	if Fact.Contact.Address.Latitude != "" && Fact.Contact.Address.Longitude != "" {
		Fact.Contact.Address.Location = fmt.Sprintf("%s,%s", Fact.Contact.Address.Latitude, Fact.Contact.Address.Longitude)
	}
	_, err := client.Index().
		Index("facts").
		Type("fact").
		BodyJson(Fact).
		Do()
	if err != nil {
		return err
	}

	return nil
}
Example #3
0
// Index indexes a contact into elasticsearch
func index(Contact *models.Contact, s *elastic.Client) error {
	id := strconv.Itoa(int(Contact.ID))
	if id == "" {
		logs.Error("id is nil")
		return errors.New("id is nil")
	}

	_, err := s.Index().
		Index("contacts").
		Type("contact").
		Id(id).
		BodyJson(Contact).
		Do()
	if err != nil {
		logs.Critical(err)
		return err
	}

	logs.Debug("Indexed")

	return nil
}