2015-05-30 44 views
1

我正在尝试使用elasticsearch来增强用Lucene实现的图像搜索项目。我很难找到一种方法来配置elasticsearch,使索引字段具有Lucene IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS在elasticsearch中,如何使索引字段具有lucene IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS?

工作的Lucene索引代码是:

Document doc = new Document(); 

FieldType myFieldType = new FieldType(); 

myFieldType.setIndexed(true); 
myFieldType.setOmitNorms(true); 
myFieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); // tell indexer to store image token's positions, offsets, and payloads 

myFieldType.setStored(false); 
myFieldType.setTokenized(true); 
myFieldType.freeze(); 

doc.add(new Field("tokens", tokenStream_w_payload, myFieldType)); 

indexWriter.addDocument(doc); 

我没有问题使我的分析,我的查询处理程序elasticsearch插件,但使用默认elasticsearch设置,我不能得到任何信息的位置,偏移和来自Lucene TermsEnumDocsAndPositionsEnum对象的有效载荷从我可以在其中看到的标记索引的AtomicReaderContext初始化。

+0

我正在关注elasticsearch文档并使用各种建议值与字段映射设置“index_options”一起玩: –

+0

我正在关注elasticsearch菜单https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping- core-types.html并使用各种建议值与字段映射设置“index_options”一起播放。 它没有帮助。例如, 卷曲-s -XPUT的 'http://本地主机:9200 /测试/' -D“{ “映射”:{ “测试”:{ “属性”:{ “令牌”:{ “类型”: “串”, “索引”: “分析”, “存储”: “是”, “term_vector”: “with_positions_offsets_payloads”, “index_options”: “偏移” } } } } }' –

回答

0

我自己找到答案。

看来我必须实现并插入我自己的分析器。常见的分析仪接缝不能产生和支持补偿和有效载荷。

这是我的工作领域的映射:

curl -XPUT "http://localhost:9200/sm101" -d' 
    { 
     "mappings": { 
     "sample": { 
      "properties": { 

      "DOC_ID" : {"type" : "integer", "store" : "yes" }, 
      "NAME" : {"type" : "string", "store" : "yes" }, 

      "tokens": { 
       "type": "string", 
       "store" : "yes", 
       "index" : "analyzed", 
       "analyzer": "image_starmap", 

       "index_options" : "offsets",   

       "term_vector": "with_positions_offsets_payloads" 
      }, 

      "filepath" : { 
       "type": "string", 
       "store" : "yes", 
       "index" : "analyzed" 
      } 
      } 
     } 
     } 
    }' 

它与我的图片搜索的复杂ImageStarmapSpansQuery很好地工作。