0

I have indexed my module to elastic search but it throws the error:

All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field.
Offending index is '<advertisement.search_indexes.ProductIndex object at 0x7f42f57e4db8>'.

I gave my code below:

Modles.py

class Product(models.Model):
user = models.ForeignKey(User)
photo = models.ImageField(upload_to='static/img',blank=True)
category = models.ForeignKey(Category,null=False)
subcategory = models.ForeignKey(SubCategory,null=False)
title = models.CharField(max_length=200)
condition = models.CharField(max_length=25,choices=condition,default='used') 
description = models.TextField(max_length=20, verbose_name="Describe what makes your ad unique:*")
price = models.FloatField(default='$',help_text=".00") 
addtype = models.CharField(max_length=25,choices=STATE_CHOICES,default="seller") 
you_are = models.CharField(max_length=20,choices=you,default="individual")
you_name = models.CharField(max_length=20)
you_email = models.CharField(max_length=30)
you_phone = models.CharField(max_length=12)
timestamp = models.DateTimeField(auto_now=True)
city=models.ForeignKey(City)
locality=models.ForeignKey(Locality)
cars=models.OneToOneField(Cars,null=True,blank=True)
mobile = models.OneToOneField(Mobiles,null=True,blank=True)
tablets = models.OneToOneField(Tablets,null=True,blank=True)
access = models.OneToOneField(Access,null=True,blank=True)

def __unicode__(self):
    return self.title

forms.py

class ProductSearchForm(SearchForm):

def no_query_found(self):
    return self.searchqueryset.all()

search_index.py

lass ProductIndex(indexes.SearchIndex, indexes.Indexable):
title = indexes.CharField(document=True,model_attr='title')
timestamp = indexes.DateTimeField(model_attr='timestamp')

def get_model(self):
    return Product

def index_queryset(self, using=None):
    """Used when the entire index for model is updated."""
    return self.get_model().objects.filter(timestamp__lte=timezone.now())

note_text.txt

{{ object.title }}
{{ object.price }}
{{ object.description }}
4
  • This is presumably Haystack. The fact that you're using elasticsearch underneath that is irrelevant. Commented Jan 29, 2015 at 10:14
  • cant understand..i m new for elasticsearch. i want to search my product by using elasticsearch. so wat i have to do Commented Jan 29, 2015 at 10:26
  • None of this code has anything whatsoever to do with elasticsearch. You are using Haystack, yes? That's where the SearchIndex class etc come from. Commented Jan 29, 2015 at 10:27
  • yes, i m using haystack..ok how to implement the search concept in python project Commented Jan 29, 2015 at 12:46

1 Answer 1

2

In search_index.py replace the line title = indexes.CharField(document=True,model_attr='title') with text = indexes.CharField(document=True,model_attr='title')

This should make it work

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.