2017-06-21 68 views
1

如果查询Brid我想<em>Brid</em>gitte中突出显示的字段,而不是整个字<em>Bridgitte</em>弹性搜索凸显,而不是单词的一部分,整个单词

我的指数看起来像这样(我已经添加NGRAM分析仪这里Highlighting part of word in elasticsearch建议)

{ 
"myindex": { 
    "aliases": {}, 
    "mappings": { 
     "mytype": { 
      "properties": { 
       "myarrayproperty": { 
        "properties": { 
         "mystringproperty1": { 
          "type": "string", 
          "term_vector": "with_positions_offsets", 
          "analyzer": "index_ngram_analyzer", 
          "search_analyzer": "search_term_analyzer" 
         }, 
         "mystringproperty2": { 
          "type": "string", 
          "term_vector": "with_positions_offsets", 
          "analyzer": "index_ngram_analyzer", 
          "search_analyzer": "search_term_analyzer" 
         } 
        }, 
        "mylongproperty": { 
         "type": "long" 
        }, 
        "mydateproperty": { 
         "type": "date", 
         "format": "strict_date_optional_time||epoch_millis" 
        }, 
        "mystringproperty3": { 
         "type": "string", 
         "term_vector": "with_positions_offsets", 
         "analyzer": "index_ngram_analyzer", 
         "search_analyzer": "search_term_analyzer" 
        }, 
        "mystringproperty4": { 
         "type": "string", 
         "term_vector": "with_positions_offsets", 
         "analyzer": "index_ngram_analyzer", 
         "search_analyzer": "search_term_analyzer" 
        } 
       } 
      } 
     }, 
     "settings": { 
      "index": { 
       "creation_date": "1498030893611", 
       "analysis": { 
        "analyzer": { 
         "search_term_analyzer": { 
          "filter": "lowercase", 
          "type": "custom", 
          "tokenizer": "ngram_tokenizer" 
         }, 
         "index_ngram_analyzer": { 
          "filter": ["lowercase"], 
          "type": "custom", 
          "tokenizer": "ngram_tokenizer" 
         } 
        }, 
        "tokenizer": { 
         "ngram_tokenizer": { 
          "token_chars": ["letter", "digit"], 
          "min_gram": "1", 
          "type": "nGram", 
          "max_gram": "15" 
         } 
        } 
       }, 
       "number_of_shards": "5", 
       "number_of_replicas": "1", 
       "uuid": "e5kBX-XRTKOqeAScO1Fs0w", 
       "version": { 
        "created": "2040499" 
       } 
      } 
     }, 
     "warmers": {} 
    } 
} 

}

这是嵌入Elasticsearch情况下,不知道这是否是相关的。

我的查询看起来像这样

MatchQueryBuilder queryBuilder = matchPhrasePrefixQuery("_all", query).maxExpansions(50); 
final SearchResponse response = client.prepareSearch("myindex") 
    .setQuery(queryBuilder) 
    .addHighlightedField("mystringproperty3", 0, 0) 
    .addHighlightedField("mystringproperty4", 0, 0) 
    .addHighlightedField("myarrayproperty.mystringproperty1", 0, 0) 
    .setHighlighterRequireFieldMatch(false) 
    .execute().actionGet(); 

而且这是行不通的。我试图改变查询queryStringQuery,但它似乎不支持搜索部分的单词。有什么建议么?

回答

1

这是不可能的。弹性搜索可以对单词进行索引。从标记化的角度来看,你在这里做不了多少。

您可能需要将包装器写在搜索结果上。 (非弹性搜索特定)

相关问题