Detailed documentation and mapping of Elasticsearch

table of Contents

Doc

Document form-Json form

Metadata

Determine if the document exists

Map

Type description

Create a mapping 

View map


 

Doc

 

Document form-Json form

Among them, card is a complex object, nested Card object.

{
  "_index": "haoke",
  "_type": "user",
  "_id": "1005",
  "_version": 1,
  "_score": 1,
  "_source": {
    "id": 1005,
    "name": "孙七",
    "age": 37,
    "sex": "女",
    "card": {
      "card_number": "123456789"
   }
 }
}

 

Metadata

A document is more than data. It also contains metadata-information about the document. The three required metadata nodes are:

Id needs special attention here

id is just a string . When it is combined with _index and _type, it can uniquely identify a document in Elasticsearch . When creating a
document, you can customize _id or let Elasticsearch automatically generate it for you (32-bit length).

 

Determine if the document exists

If we only need to judge whether the document exists, instead of querying the document content, we can do this

 

 

Map

 

Mapping is the process of defining a document, which fields the document contains, whether these fields are saved, whether they are indexed, whether they are word segmented, etc.

 

Type description

The indexes we created and the inserted documents are automatically determined by Elasticsearch. Sometimes, we need to specify the field type. Otherwise, the type of automatic judgment does not match the actual needs.

 

 

 

 

 

Create a mapping 

  • grammar
PUT /索引库名/_mapping/类型名称
{
  "properties": {
    "字段名": {
      "type": "类型",
      "index": true,
      "store": true,
      "analyzer": "分词器"
    }
  }
}
  • meaning

Type name: It is the concept of the type mentioned above, similar to the field names of different tables in the database: fill in arbitrarily, you can specify many attributes, for example:

type: type, which can be text, long, short, date, integer, object, etc.

index: whether to index, the default is true

store: whether to store, the default is false

analyzer: tokenizer, here ik_max_wordis to use ik tokenizer

  • Request result
PUT heima/_mapping/goods
{
  "properties": {
    "title": {
      "type": "text",
      "analyzer": "ik_max_word"
    },
    "images": {
      "type": "keyword",
      "index": "false"
    },
    "price": {
      "type": "float"
    }
  }
}
  • Response results
{
  "acknowledged": true
}

 

View map

       grammar 

GET /索引库名/_mapping

       Examples

GET /heima/_mapping

       response 

{
  "heima": {
    "mappings": {
      "goods": {
        "properties": {
          "images": {
            "type": "keyword",
            "index": false
          },
          "price": {
            "type": "float"
          },
          "title": {
            "type": "text",
            "analyzer": "ik_max_word"
          }
        }
      }
    }
  }
}
Published 568 original articles · Like 180 · Visits 180,000+

Guess you like

Origin blog.csdn.net/Delicious_Life/article/details/105515502