elastic-search 笔记

ReZero lol
  1. A good place to start is with batches of 1,000 to 5,000 documents and a total payload between 5MB and 15MB.

  2. hits._score - the document’s relevance score (not applicable when using match_all)

  3. Each search request is self-contained: Elasticsearch does not maintain any state information across requests.

  4. must or should clause contributes to the document’s relevance score while must_not clause is treated as a filter

    • You can also explicitly specify arbitrary filters to include or exclude documents based on structured data
  5. The first alternative is to have an index per document type. Instead of storing tweets and users in a single twitter index, you could store tweets in the tweets index and users in the user index. Indices are completely independent of each other and so there will be no conflict of field types between indices. This approach has two benefits:

    • Data is more likely to be dense and so benefit from compression techniques used in Lucene.
    • The term statistics used for scoring in full text search are more likely to be accurate because all documents in the same index represent a single entity.
  6. Each index can be sized appropriately for the number of documents it will contain: you can use a smaller number of primary shards for users and a larger number of primary shards for tweets.

request
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
PUT twitter
{
"mappings": {
"_doc": {
"properties": {
"type": { "type": "keyword" },
"name": { "type": "text" },
"user_name": { "type": "keyword" },
"email": { "type": "keyword" },
"content": { "type": "text" },
"tweeted_at": { "type": "date" }
}
}
}
}

PUT twitter/_doc/user-kimchy
{
"type": "user",
"name": "Shay Banon",
"user_name": "kimchy",
"email": "shay@kimchy.com"
}

PUT twitter/_doc/tweet-1
{
"type": "tweet",
"user_name": "kimchy",
"tweeted_at": "2017-10-24T09:00:00Z",
"content": "Types are going away"
}

GET twitter/_search
{
"query": {
"bool": {
"must": {
"match": {
"user_name": "kimchy"
}
},
"filter": {
"match": {
"type": "tweet"
}
}
}
}
}
  • Post title:elastic-search 笔记
  • Post author:ReZero
  • Create time:2020-12-13 20:21:00
  • Post link:https://rezeros.github.io/2020/12/13/elastic-search/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments
Contents