小编anu*_*sza的帖子

Django haystack在弹性搜索中将LocationField创建为字符串而不是geo_point

我正在使用django 1.8.9,django-rest-framework,django-haystack和Elasticsearch,并且我正在尝试使LocationField正常工作,但是创建索引但是类型始终string不是geo_point,所以很明显没有地理搜索工作.

settings.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.gis',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django_extensions',
    'elasticsearch',
    'rest_framework',
    'haystack',
)
Run Code Online (Sandbox Code Playgroud)

requirements.txt:

Django==1.8.9
django-appconf==1.0.1
django-compressor==1.6
django-extensions==1.6.1
django-filter==0.11.0
django-haystack==2.4.1
djangorestframework==3.3.1
djangorestframework-jwt==1.7.2
ecdsa==0.13
elasticsearch==2.2.0
Fabric==1.10.2
future==0.15.2
geopy==1.11.0
gunicorn==19.4.1
Markdown==2.6.5
paramiko==1.16.0
psycopg2==2.6.1
pycrypto==2.6.1
PyJWT==1.4.0
python-dateutil==2.4.2
python-memcached==1.57
setproctitle==1.1.9
six==1.10.0
urllib3==1.14
Run Code Online (Sandbox Code Playgroud)

search_indexes.py:

from haystack import indexes
from blah.api.models import MyModel


class MyIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    description = indexes.CharField(model_attr='description')
    location = indexes.LocationField(model_attr='get_location')
    created = indexes.DateTimeField(model_attr='created')

    def get_model(self):
        return MyModel
Run Code Online (Sandbox Code Playgroud)

MyModel上的get_location属性:

from haystack.utils.geo …
Run Code Online (Sandbox Code Playgroud)

python django django-haystack elasticsearch

3
推荐指数
1
解决办法
453
查看次数

标签 统计

django ×1

django-haystack ×1

elasticsearch ×1

python ×1