Take a very simple type under Index without a word:

Note that the original structure is plural, so JSON can hold several types of mappings:

{
    "mappings": {"transfer": {"properties": {"loveCount": {"index":"not_analyzed"."type":"string"
                },
                "test": {"index":"not_analyzed"."type":"string"
                },
                "id": {"index":"not_analyzed"."type":"string"}}},"goods": {... anothertype}}}Copy the code

Now, our same transfer should be written as follows according to the new standard:

Mapping

PUT /transfer
{
  "mappings": {
    "properties": {
      "loveCount":    { "type": "keyword" }, 
      "test":  { "type": "keyword"  },
      "id":   { "type": "text"}}}}------response------

{
  "acknowledged" : true."shards_acknowledged" : true."index" : "transfer"
}
Copy the code

  • Keyword is the equivalent of not_analyzed. Text preanalyzes words, inverts the index, and uses the default one without specifying a word divider.

  • Only one MAPPING is supported under the ES7 index.

For a more complex example of the word segmentation we used in 2.2, write a new document against the following:

Test an analyzer | Elasticsearch Reference [7.x] | Elastic

  • There are also some ways to use a custom word divider

Mapping

{
    "inventory": {"properties": {"genTime": {"format":"YYYY-MM-dd HH:mm:ss"."type":"date"
            },
            "rowId": {"index":"not_analyzed"."type":"string"
            },
            "listId": {"analyzer":"whitespace"."type":"string"
            },
            "createTime": {"format":"YYYY-MM-dd HH:mm:ss"."type":"date"}}}}Copy the code

ElasticSearch 7.x should look like this:

PUT /inventory
{
  "mapping": {
    "properties": {
      "genTime": {
        "type": "date"."format": "yyyy-MM-dd HH:mm:ss"
      },
      "listId": {
        "type": "text"."analyzer": "whitespace"
      },
      "rowId": {
        "type": "keyword"}}}}-----respose-----

{
  "acknowledged" : true."shards_acknowledged" : true."index" : "inventory"
}
Copy the code
  • Tips: The date format can now be written like this:
PUT my_index
{
  "mappings": {
    "properties": {
      "date": {
        "type":   "date"."format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"}}}}Copy the code

The Date datatype | Elasticsearch Reference [7.4] | Elastic

I think the benefit of writing this way is to reduce the occurrence of failed search problems when saving the document due to the neglect of the time format.

And adjusted the function of index in document, which was used to specify whether or not a word should be split, and which word should be used. Now it is:

Now it is time to decide whether to index and search the field.

Through the above, es 2.x forced upgrade to 7.x has a certain certainty. There was a “single node smooth migration” for every major release, but we ran up so much technical debt that we missed 5.x 6.x 7.x. The official advice was to upgrade 2.x first to 5.8 and then to 6.x and so on. I would never do that.

Github Archive: github.com/pkwenda/Blo…