2015-05-30 48 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很好地工作。