settings.py
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}
search_indexes.html
class VehicleIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
garage = indexes.EdgeNgramField(model_attr='garage')
plate_number = indexes.EdgeNgramField(model_attr='plate_number')
chassis_number = indexes.CharField(model_attr='chassis_number')
brand = indexes.EdgeNgramField(model_attr='brand')
model = indexes.CharField(model_attr='model')
def get_model(self):
return Vehicle
def index_queryset(self, using=None):
return self.get_model().objects.all()
示例:
>>>>>>有什么不对?为什么忽略部分单词搜索?
其他信息
我发现了这个,但没有用:link
我认为elasticsearch_backend.py中的haystack中存在一个错误 没有正确使用pyelasticsearch第868行看起来像:
self.conn.put_mapping('modelresult', current_mapping, index=self.index_name)
如果您将其替换为:
self.conn.put_mapping(doc_type='modelresult', mapping=current_mapping, index=self.index_name)
这是pyelasticsearch的预期,然后你会看到 edgengram_analyzer将添加到EdgeNgramField字段中。至少它 适合我。
更新
在elasticsearch日志中找到了这个
[2016-04-15 09:01:36,164][DEBUG][action.admin.indices.mapping.put] [Eliminator] failed to put mappings on indices [[haystack]], type [modelresult]
MapperParsingException[Root mapping definition has unsupported parameters: [_boost : {name=boost, null_value=1.0}]]
at org.elasticsearch.index.mapper.DocumentMapperParser.checkNoRemainingFields(DocumentMapperParser.java:171)
at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:159)
at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:99)
at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:498)
at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.applyRequest(MetaDataMappingService.java:257)
at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.execute(MetaDataMappingService.java:230)
at org.elasticsearch.cluster.service.InternalClusterService.runTasksForExecutor(InternalClusterService.java:468)
at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:772)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
[2016-04-15 09:08:22,657][WARN ][http.netty ] [Eliminator] Caught exception while handling client http traffic, closing connection [id: 0x5e3f8728, /127.0.0.1:51927 => /127.0.0.1:9200]
java.io.IOException: Connessione in corso interrotta forzatamente dall'host remoto
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(Unknown Source)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.read(Unknown Source)
at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:64)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)