spring-data-elasticsearch (elasticsearch 6.7.0) @Document Detailed annotations and @Field

Version: elasticsearch 6.7.0  

maven package:

<dependency>
 <groupId>org.springframework.data</groupId>
 <artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
 <groupId>org.elasticsearch.client</groupId>
 <artifactId>elasticsearch-rest-high-level-client</artifactId>
 <version>6.7.0</version>
</dependency>

  

@Document notes:

@interface the Document {public 
 
String indexName (); // index library name, the name of the individual recommendations to the project named 
 
String type () default ""; // type of personal recommendations to the name of the entity named 
 
short shards () default 5; // default number of partitions 
 
short replicas () default 1; // default backup each partition number 
 
String refreshInterval () default "1s" ; // refresh interval 
 
String indexStoreType () default "fs" ; // index file storage type 
}

@Field notes:

@interface Field, {public 
 
FieldType type () default FieldType.Auto; // automatically detects the type attribute can be set according to actual situation 
 
FieldIndex index () default FieldIndex.analyzed; // default word case, like general default word, unless you do not use this field to determine the query 
 
DateFormat format () default DateFormat.none; // time type of format 
 
String pattern () default ""; 
 
boolean store () default false; // default does not store the original case 
 
String searchAnalyzer () default ""; // word for use when the specified field search 
 
String indexAnalyzer () default ""; // specified when specifying field to establish an index word 
 
String [] ignoreFields () default { }; // if a field that needs to be ignored 
 
boolean includeInParent (default false); 
}

FieldType type:

public enum FieldType {
	Text,  
	Integer,
	Long,
	Date,
	Float,
	Double,
	Boolean,
	Object,
	Auto,
	Nested,
	Ip,
	Attachment,
	Keyword
}

 

Text Type: full text index field, such as e-mail text description or product description. These fields are converted into a single string parser list of terms. Es analysis procedure allows a single search the full text of each word in the domain. Text fields are not used to sort, rarely used in the polymerization 
Object type: a Json document is hierarchical in nature, the document may contain internal objects, and these objects and may contain internal object itself.
{ 
  "region": "US",
  "manager": { 
    "age":     30,
    "name": { 
      "first": "John",
      "last":  "Smith"
    }
  }
}

  

Nested type: nested type is a special version of the object data types, he allowed an array of objects in a manner independent of one another query index

PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "user": {
          "type": "nested" 
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "group" : "fans",
  "user" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}

GET my_index/_search
{
  "query": {
    "nested": {
      "path": "user",
      "query": {
        "bool": {
          "must": [
            { "match": { "user.first": "Alice" }},
            { "match": { "user.last":  "Smith" }} 
          ]
        }
      }
    }
  }
}

GET my_index/_search
{
  "query": {
    "nested": {
      "path": "user",
      "query": {
        "bool": {
          "must": [
            { "match": { "user.first": "Alice" }},
            { "match": { "user.last":  "White" }} 
          ]
        }
      },
      "inner_hits": { 
        "highlight": {
          "fields": {
            "user.first": {}
          }
        }
      }
    }
  }
}

  Ip type: ip fields can be indexed and stored IPV4 and IPv6 address

PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "ip_addr": {
          "type": "ip"
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "ip_addr": "192.168.1.1"
}

GET my_index/_search
{
  "query": {
    "term": {
      "ip_addr": "192.168.0.0/16"
    }
  }
}

 

Keyword Type: means for indexing structured content (e.g., email address, host name, status code, zip code, etc.) of the field. They are usually used to filter, sort, aggregate. Keyword fields can only be searched depending on the exact value of the period,

 

 

 




Elasticsearch analysis process allows each full-text search for a single word in the domain. Sorting the text field is not used, rarely used for polymerization (

Guess you like

Origin www.cnblogs.com/durenniu/p/11404247.html