Elasticsearch- arrays and multi-field

And an array of multi-field ES-

When you need to need to have multiple values ​​in the same field, the array will be used.

Array

If you have more than one index field values, these values can be placed in square brackets.
In the album under the type of music in the index, adding songs in the song list field, memory album

FengZhendeMacBook-Pro:bin FengZhen$ curl -XPUT 'localhost:9200/music/album/1?pretty' -d '{

> "Name": "Eight Dimensions"

> "date":"2002-07-18",

> "Songs": [ "Orc", "back in time", "Milan small blacksmith," "The Last Battle"]

> }'

{

  "_index" : "music",

  "_type" : "album",

  "_id" : "1",

  "_version" : 2,

  "_shards" : {

    "total" : 2,

    "successful" : 1,

    "failed" : 0

  },

  "created" : false

}

 

Mapping field defined as a string of songs, and treated in the same single value

FengZhendeMacBook-Pro:bin FengZhen$ curl 'localhost:9200/music/_mapping/album?pretty'
{
  "music" : {
    "mappings" : {
      "album" : {
        "properties" : {
          "date" : {
            "type" : "date",
            "format" : "strict_date_optional_time||epoch_millis"
          },
          "downloadable" : {
            "type" : "boolean"
          },
          "format_date" : {
            "type" : "date",
            "format" : "MMM DD YYYY"
          },
          "name" : {
            "type" : "string"
          },
          "singer" : {
            "type" : "string"
          },
          "songs" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

 

All core types are supported an array, without modifying the map, using either a single value, you can also use an array. For Lucene internal processing, both basically the same, in the same field entries in the index more or less, depends entirely on how much value is provided.

Multi-Field

Multi-field allows different settings for an index with data multiple times. Such as: In the above example the use of the type of album the album in two different options to configure songs fields: analyzed, matching, and not_analyzed for each word, an exact match for the full name of the song.
No need to re-index data, will be able to upgrade a single field to multiple fields. Once the sub-field already exists, it can not be erased.
Set string type multiple-field: one is analyzed, once not_analyzed

curl -XPUT 'localhost:9200/music/_mapping/album?pretty' -d '{
    "album":{
        "properties":{
            "songs":{
                "type":"string",
                "index":"analyzed",
                "fields":{
                    "verbatim":{
                        "type":"string",
                        "index":"not_analyzed"
                    }
                }
            }
        }
    }
}'

The default list of songs fields are analyzed, it will provide the text is converted to lowercase, and cut into words.
The second field songs.verbatim is not_analyzed, the original label as a single entry process
to be analyzed version of the song search field, just like other search strings the same. If you want to search not_analyzed version of field (only an exact match of the original songs), it is necessary to specify the full path songs.verbatim.
Multi-field and an array of field values are allowed to have multiple core types in a single field.

 

Guess you like

Origin www.cnblogs.com/EnzoDin/p/11100208.html