es 색인 및 데이터 구조 및 기타 지식 사용

1:es   색인 과 데이터 구조 맵
- es 색인 설명: 
색인 구조: index/type/id   
대응 하 는 관계 형 데이터베이스 구조  index = database , type = table , id = id 
묵인
-- 새로운 색인 삽입
PUT test-index/default/1
{
  "test":"one",
  "other":1
}
-- 검색 색인 과 데이터 구조
GET test-index/_mapping?pretty
결과
{
  "test-index": {
    "mappings": {
      "default": {
        "properties": {
          "other": {
            "type": "long"
          },
          "test": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}
-- 해명
es 는 필드 형식 을 분석 하고 패턴 과 일치 합 니 다. test 의 필드 는 string 이 고 other 필드 는 long 입 니 다.
mapping - 맵 과 데이터 구조 정의 
mapping 은 하나 이상 의 analyzer (분사 기) 로 구성 되 어 있 으 며, analyzer 는 하나 이상 의 filter 로 구성 되 어 있 습 니 다. ES 색인 문서 일 때 필드 의 내용 은 analyzer 에 전달 되 고, 부분 집합 filter 를 통 해 데이터 변환 (분사, 색인 등 작업) 을 합 니 다.
-- 사용자 정의 매 핑
PUT newindex
{
  "mappings": {
      "default": {
        "properties": {
          "name": {
            "type": "text"
          },
          "age": {
            "type": "long"
          }
        }
      }
    }
}
-- 설명
색인 newIndex - name 을 text 로 지정 하고 age 는 long 을 지정 합 니 다.
-- 살펴보다
GET newIndex/_mapping?pretty
-- 테스트
PUT newindex/default/1
{
  "name":"xxx",
  "age":"xxx"
}
결국
mapper_parsing_exception
failed to parse [age]
-- 테스트 2
PUT newindex/default/1
{
  "name":"xxx",
  "age":11
}
결국
"created": true
2:es  binary 데이터 형식 지원
원리
이 binary 형식 은 Base 64 인 코딩 문자열 로 바 이 너 리 값 을 받 습 니 다. 이 필드 는 기본적으로 저장 되 지 않 으 며 검색 할 수 없습니다.
-- 사용
PUT my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "name": {
          "type": "text"
        },
        "blob": {
          "type": "binary" ,
          "doc_values" : true
        }
      }
    }
  }
}
PUT my_index/_doc/1
{
  "name": "Some binary blob",
  "blob": "U29tZSBiaW5hcnkgYmxvYg==" 
}

플러그 인 에서 가 져 오기
final ScriptDocValues.BytesRefs bytesRefs = (ScriptDocValues.BytesRefs)doc().get("
blob");
byte[] binary = bytesRefs.getValue().bytes;
3: es 중국어 단어 기 설치 및 사용   
-- 이곳 은 깃 허브 에서 운반  원래 github 주소https://github.com/medcl/elasticsearch-analysis-ik
-- 설치
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.2/elasticsearch-analysis-ik-6.2.2.zip
-- 사용
1.create a index
curl -XPUT http://localhost:9200/index
2.create a mapping
curl -XPOST http://localhost:9200/index/fulltext/_mapping -H 'Content-Type:application/json' -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }
    
}'
3.index some docs
curl -XPOST http://localhost:9200/index/fulltext/1 -H 'Content-Type:application/json' -d'
{"content": "미국 이 이라크 에 남 긴 것 은 난 장 판 입 니까?"}
'
curl -XPOST http://localhost:9200/index/fulltext/2 -H 'Content-Type:application/json' -d'
{"content": "공안 부: 각 지역 의 스쿨버스 는 최고 도로 권 을 누 릴 것 입 니 다"}
'
curl -XPOST http://localhost:9200/index/fulltext/3 -H 'Content-Type:application/json' -d'
{"content": "한 중 어 경 충돌 조사: 한 경 매일 평균 1 척 중국 어선 억류"}
'
curl -XPOST http://localhost:9200/index/fulltext/4 -H 'Content-Type:application/json' -d'
{"content": "로스앤젤레스 주재 중국 영사관 이 아시아 계 남자 에 게 총격 을 당 한 용의 자 는 자수 했다"}
'
4.query with highlighting
curl -XPOST http://localhost:9200/index/fulltext/_search  -H 'Content-Type:application/json' -d'
{
    "query": {"match": {"content": "중국"},
    "highlight": {
        "pre_tags": ["", ""],
        "post_tags": ["", ""],
        "fields": {
            "content": {}
        }
    }
}
'
Result
{
    "took": 14,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 2,
        "hits": [
            {
                "_index": "index",
                "_type": "fulltext",
                "_id": "4",
                "_score": 2,
                "_source": {
                    "콘 텐 츠": "로스앤젤레스 주재 중국 영사관 에서 아시아 계 남자 총격 용의자 자수"
                },
                "highlight": {
                    "content": [
                        "로스앤젤레스 주재 중국 영사관 이 아시아 계 남자 에 게 총격 을 당 한 용의 자 는 자수 했다."
                    ]
                }
            },
            {
                "_index": "index",
                "_type": "fulltext",
                "_id": "3",
                "_score": 2,
                "_source": {
                    "콘 텐 츠": "한 중 어 경 충돌 조사: 한 경 하루 평균 1 척 중국 어선 억류"
                },
                "highlight": {
                    "content": [
                        "매일 중국 어선 1 척 씩 압수 해 요".
                    ]
                }
            }
        ]
    }
}
4:es  색인 템 플 릿
장면
여러 개의 유사 한 구조의 색인 데 이 터 를 정의 할 때 사용 합 니 다.
색인 세그먼트 저장 소
my * 라 는 이름 은 my 를 접두사 로 하 는 모든 색인 을 구조 적 으로 매 핑 합 니 다.
-- 사용
PUT _template/my_template{    "template": "my-*",    "order": 0,    "settings": {         "number_of_shards": 10,  "number_of_replicas": 0    },    "mappings": {
      "default": {
  "_all": {
        "enabled": false
      }

        "properties": {
          "name": {
            "type": "text"
          },
          "age": {
            "type": "long"
          }
        }
    }
  }
}
5:es   캐 시 조회
원리
-- 사용
6:es  블록 버스터 와 조회
-- 원리 와 의미
-- 합 리 적 사용
7: es 시스템 모니터링 도구 설치 x - pack 
이 글 을 볼 수 있 습 니 다.http://blog.csdn.net/ailice001/article/details/79474290

좋은 웹페이지 즐겨찾기