简体   繁体   English

在Elasticsearch中禁用文档中所有字段的索引字段

[英]Disable indexing fields for all fields in the document in Elasticsearch

  • am using elasticsearch in my Java Spring application, for working with elasticsearch Spring JPA is used. 在我的Java Spring应用程序中使用elasticsearch,用于与Elasticsearch配合使用Spring JPA。 I have a document and corresponding class in java with all fields that should not be indexed (I search through them for exact match using termFilter statement in java api) In my case I have to annotate each field 我在Java中有一个文档和相应的类,其中的所有字段都不应编入索引(我使用java api中的termFilter语句搜索它们以查找完全匹配)在我的情况下,我必须注释每个字段

    @Field(type = FieldType.String, index = FieldIndex.not_analyzed) @Field(类型= FieldType.String,索引= FieldIndex.not_analyzed)

and I get something like this 我得到这样的东西

@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;


}

Is there a possibility to put annotation on class in order not to duplicate it above all fields? 是否可以在类上添加注释,以免在所有字段上方重复注释?

You can achive your goal without @Field annotations using raw mappings + dynamic templates 您可以使用原始映射+ 动态模板在没有@Field批注的情况下实现目标
Specify the path to your mappings in json file using @Mapping annotation 使用@Mapping注解在json文件中指定映射的路径

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

Then in mappings.json define your mapping like this: 然后在mappings.json定义您的映射,如下所示:

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

Note: I didn't test it, so please check for typos. 注意:我没有测试它,所以请检查错别字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部分更新文档中的字段-findAndModify删除所有其他字段? - partially update fields in a document - findAndModify remove all other fields? 禁用Java中的按钮,直到所有字段都填满 - Disable button in Java until all fields filled 在列表中获取文档中的所有字段-Firestore Java - Get all fields in a document in a list - Firestore Java 如何在视图中显示文档的所有字段? - How to show all fields of a document in view? 当Elasticsearch批量操作失败时,如何获取文档字段? - How to get document fields when a failure happens in an Elasticsearch bulk operation? 我们是否可以避免将所有字段映射到 springdata 中的实体类以进行弹性搜索,因为我在 json 文档中有 100 多个字段? - Can we avoid mapping all the fields to entity class in springdata for elasticsearch, as I have more than 100 field in the json document? 在母类的 ArrayList 中索引子类的字段并显示所有字段 - indexing a child class's fields in a mothers class's ArrayList and display all the fields 将格式为“ dd-MM-yyyy HH:mm:ss”的日期字段索引到ElasticSearch 2.2.1中 - Indexing date fields with format “dd-MM-yyyy HH:mm:ss” into ElasticSearch 2.2.1 在 elasticsearch 中检索单个字段 - retrieving individual fields in elasticsearch Elasticsearch按嵌套字段分组 - Elasticsearch grouping by nested fields
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM