0
  • 上午在我的Java Spring應用程序中使用elasticsearch來處理elasticsearch使用Spring JPA。 我在用java不應該被索引 在我的情況(我通過他們使用的Java API termFilter聲明搜索精確匹配)我有標註每場禁用Elasticsearch中文檔中所有字段的索引字段

    @Field(所有字段的文檔和相應的類類型= FieldType.String,指數= FieldIndex.not_analyzed)

,我得到這樣的

@JsonInclude(JsonInclude.Include.NON_NULL) 
@JsonIgnoreProperties(ignoreUnknown = true) 
@Document(indexName = "message", type = "message") 
public class Message implements Serializable { 

    @Id 
    @NotNull 
    @JsonProperty("id") 
    private String id; 

    @JsonProperty("userName") 
    @Field(type = FieldType.String, index = FieldIndex.not_analyzed) 
    private String userName; 


    @NotNull 
    @JsonProperty("topic") 
    @Field(index = FieldIndex.not_analyzed, type = FieldType.String) 
    private String topic; 

    @NotNull 
    @JsonProperty("address") 
    @Field(index = FieldIndex.not_analyzed, type = FieldType.String) 
    private String address; 

    @NotNull 
    @JsonProperty("recipient") 
    @Field(index = FieldIndex.not_analyzed, type = FieldType.String) 
    private String recipient; 


} 

有沒有把註釋階級爲了不重複它上面的可能性所有領域?

回答

1

您可以achive自己的目標,而無需使用原始映射+ dynamic templates
指定的路徑,在JSON文件的映射@Field註釋使用@Mapping註釋

@Mapping(mappingPath = "/mappings.json") 

然後在mappings.json定義這樣的映射:

{ 
    "mappings": { 
    "message": { 
     "dynamic_templates": [ 
      { "notanalyzed": { 
        "match":    "*", 
        "match_mapping_type": "string", 
        "mapping": { 
         "type":  "string", 
         "index":  "not_analyzed" 
        } 
       } 
      } 
      ] 
     } 
    } 
} 

注:我沒有測試它,所以請檢查錯別字。

相關問題