Elasticsearch difference in the text with the keyword

After ES updated to version 5, the abolition of string data type, instead it is the keyword and text data types text and keyword so what difference does it?

adding data

Use bulk es database to add some bulk document

POST /book/novel/_bulk
{"index": {"_id": 1}}
{"name": "Gone with the Wind", "author": "Margaret Mitchell", "date": "2018-01-01"}
{"index": {"_id": 2}}
{"name": "Robinson Crusoe", "author": "Daniel Defoe", "date": "2018-01-02"}
{"index": {"_id": 3}}
{"name": "Pride and Prejudice", "author": "Jane Austen", "date": "2018-01-01"}
{"index": {"_id": 4}}
{"name": "Jane Eyre", "author": "Charlotte Bronte", "date": "2018-01-02"}

View mapping

Found that name, author's type is text,
there is a field that keyword, keyword type is the keyword:

Inquire

Use a query term fiction:

GET book/novel/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "term": {
          "name": "Gone with the Wind"
        }
      },
      "boost": 1.2
    }
  }
}

What results is also not found:

Then use the name of the keyword query:

GET book/novel/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "term": {
          "name.keyword": "Gone with the Wind"
        }
      },
      "boost": 1.2
    }
  }
}

You can query to a data:

experiment

Use name can not be found, and the use name.keyword can be found, we can be judged by the following experiment:

Carried out using the name of the word, the result will be out four words:

Use name.keyword divide word, the result is only one word out:

in conclusion

text types: The word, first word processing objects, and then re-re-deposited into the es.
When using more than one word query, of course, word has been finding out the contents!

keyword: regardless of the word, not the es the objects in word processing, but credited the entire object!
This time of course be completely inquiry! The default is 256 characters!

Author: Sparrow on Xiangshan
link: https://www.jianshu.com/p/1189ff372c38
Source: Jane books
are copyrighted by the author. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

Guess you like

Origin www.cnblogs.com/sanduzxcvbnm/p/12177377.html