elasticsearch mapping demo
curl -XPUT localhost:9200/local -d '{
"settings" : {
"analysis" : {
"analyzer" : {
"stem" : {
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "stop", "porter_stem"]
}
}
}
},
"mappings" : {
"article" : {
"dynamic" : true,
"properties" : {
"title" : {
"type" : "string",
"analyzer" : "stem"
}
}
}
}
}' # Sample Analysis
curl -XGET localhost:9200/local/_analyze?analyzer=stem -d '{Fight for your life}'
curl -XGET localhost:9200/local/_analyze?analyzer=stem -d '{Bruno fights Tyson tomorrow}' # Index Data
curl -XPUT localhost:9200/local/article/1 -d'{"title": "Fight for your life"}'
curl -XPUT localhost:9200/local/article/2 -d'{"title": "Fighting for your life"}'
curl -XPUT localhost:9200/local/article/3 -d'{"title": "My dad fought a dog"}'
curl -XPUT localhost:9200/local/article/4 -d'{"title": "Bruno fights Tyson tomorrow"}' # search on the title field, which is stemmed on index and search
curl -XGET localhost:9200/local/_search?q=title:fight # searching on _all will not do anystemming, unless also configured on the mapping to be stemmed...
curl -XGET localhost:9200/local/_search?q=fight
curl -XPUT http://localhost:9200/test_index/ -d '
{
"index": {
"analysis": {
"analyzer": {
"index_analyzer": {
"tokenizer": "nGram",
"filter": ["lowercase", "snowball"]
},
"search_analyzer": {
"tokenizer": "nGram",
"filter": ["lowercase", "snowball"]
}
},
"filter": {
"snowball": {
"type": "snowball",
"language": "English"
}
}
}
}
}' curl -XPUT 'http://localhost:9200/test_index/item/_mapping' -d '
{
"item": {
"properties": {
"title": {
"type": "string",
"boost": 2.0,
"index": "analyzed",
"store": "yes",
"term_vector" : "with_positions_offsets"
},
"description": {
"type": "string",
"boost": 1.0,
"index": "analyzed",
"store": "yes",
"term_vector" : "with_positions_offsets"
},
"link": {
"type": "string"
}
}
}
}'
# curl -XDELETE http://localhost:9200/test-index # "analyzer"."default" => default name for index and search
# "tokenizer" : "standard" => splits words at punctuation characters
# http://www.elasticsearch.org/guide/reference/index-modules/analysis/ curl -XPUT http://localhost:9200/test-index/ -d '
{
"index": {
"analysis": {
"analyzer": {
"default": {
"tokenizer": "standard",
"filter": ["lowercase", "snowball"]
}
}
}
}
}' # http://www.elasticsearch.org/guide/reference/api/search/highlighting.html
# "store": "yes" => enable highlighting
# "term_vector" : "with_positions_offsets" => for performance curl -XPUT http://localhost:9200/test-index/test-item/_mapping -d '
{
"test-item": {
"properties": {
"name": {
"type": "string",
"store": "yes",
"term_vector": "with_positions_offsets"
},
"description": {
"type": "string",
"store": "yes",
"term_vector": "with_positions_offsets"
},
"field-without-highlighting": {
"type": "string"
}
}
}
}' curl -XPUT http://localhost:9200/test-index/test-item/1 -d '
{
"name": "Example One",
"description": "Create a test item for to the index.",
"field-without-highlighting": "test"
}' # "highlight" => wrap search result in <em> tags (define own tags with pre_tags/post_tags)
# "number_of_fragments": 0 => don"t split field in multiple fragments
# http://www.elasticsearch.org/guide/reference/api/search/highlighting.html curl -XGET http://localhost:9200/test-index/test-item/_search?pretty=true -d '
{
"highlight": {
"fields": {
"name": {
"number_of_fragments": 0
},
"description": {
"number_of_fragments": 0
}
}
},
"query": {
"query_string": {
"fields": ["name", "description"],
"query": "test"
}
}
}' => {
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.029424578,
"hits": [{
"_index": "test-index",
"_type": "test-item",
"_id": "1",
"_score": 0.029424578,
"_source": {
"name": "Example One",
"description": "Create a test item for to the index.",
"field-without-highlighting": "test"
},
"highlight": {
"description": ["Create a <em>test</em> item for to the index."]
}
}]
}
} curl -XGET http://localhost:9200/test-index/test-item/_search?pretty=true -d '
{
"highlight": {
"fields": {
"name": {
"number_of_fragments": 0
},
"description": {
"number_of_fragments": 0
}
}
},
"query": {
"query_string": {
"fields": ["name", "description"],
"query": "created EXAMPLES"
}
}
}' => {
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.06241896,
"hits": [{
"_index": "test-index",
"_type": "test-item",
"_id": "1",
"_score": 0.06241896,
"_source": {
"name": "Example One",
"description": "Create a test item for to the index.",
"field-without-highlighting": "test"
},
"highlight": {
"description": ["<em>Create</em> a test item for to the index."],
"name": ["<em>Example</em> One"]
}
}]
}
}
elasticsearch mapping demo的更多相关文章
- SpringBoot 2.x 整合ElasticSearch的demo
SpringBoot 2.x 整合ElasticSearch的demo 1.配置文件application.yml信息 # Tomcat server: tomcat: uri-encoding: U ...
- Elasticsearch教程(五) elasticsearch Mapping的创建
一.Mapping介绍 在Elasticsearch中,Mapping是什么? mapping在Elasticsearch中的作用就是约束. 1.数据类型声明 它类似于静态语言中的数据类型声明,比如声 ...
- Elasticsearch mapping映射文件设置没有生效
Elasticsearch mapping映射文件设置没有生效 问题背景 我们一般会预先创建 Elasticsearch index的 mapping.properties 文件(类似于MySQL中的 ...
- elasticsearch mapping问题解决
1.报错信息如下: [--16T00::,][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch ...
- ElasticSearch搜索demo
ElasticSearch版本:1.4.1 分词:ik jdk:1.7.67 开发工具:Eclipse 系统:win7 忙活了几天,使用ES做成,就是页面有点丑,demo页面如下: 1.搜索主页 2. ...
- elasticsearch Mapping 定义索引
Mapping is the process of defining how a document should be mapped to the Search Engine, including i ...
- elasticsearch mapping简单介绍
这两天一直在看elasticsearch相关的内容,看到mapping这一块,就折腾了下. 一般情况下,我们不需要对elasticsearch的mapping进行设置,但如果希望对索引使用自定义的管理 ...
- 如何设计一个高性能 Elasticsearch mapping
目录 前言 mapping mapping 能做什么 Dynamic mapping dynamic=true dynamic=runtime dynamic=false dynamic=strict ...
- Elasticsearch mapping
//设置mapping Put: http://192.168.1.102:9200/indexName { "settings": { , }, "mappings&q ...
随机推荐
- [LeetCode&Python] Problem 21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- js中三种定义变量的方式const, var, let的区别。
const var let区别 1.const 定义的变量不可以修改,而且必须初始化 const a = 3;正确 const a;错误,必须初始化 console.log("函数外c ...
- loadrunner笔记---一
1.Loadrunner主要由Vugen,Controller和Analyais3部分组成 2.简述描述集合点和集合点函数 集合点可以同步虚拟用户,以便能在同一时刻执行任务,集合点函数lr_rende ...
- 牛客国庆集训派对Day4 J-寻找复读机
链接:https://www.nowcoder.com/acm/contest/204/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 《DSP using MATLAB》Problem 6.17
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- Java基础三(Scanner键盘输入、Random随机数、流程控制语句)
1.引用类型变量的创建及使用2.流程控制语句之选择语句3.流程控制语句之循环语句4.循环高级 ###01创建引用类型变量公式 * A: 创建引用类型变量公式 * a: 我们要学的Scanner类是属于 ...
- Java基础七(Eclipse工具)
今日内容介绍1.Eclipse开发工具2.超市库存管理系统 ###01Eclipse的下载安装 * A: Eclipse的下载安装 * a: 下载 * http://www.eclipse.org ...
- Java(命令行)打印库存清单
public class demo{ public static void main(String[] args){ //1 顶部 System.out.println("--------- ...
- nodejs-hook 开发
nodejs require hook 功能很强大,我们可以用来将不支持的数据文件,直接使用require 进行加载,同时 我们可以方便的进行代码的预编译(比如babel 的组件) 为了方便使用npm ...
- cocos2d-x游戏开发 跑酷(三) 人物跑动
原创.转载请注明出处:http://blog.csdn.net/dawn_moon/article/details/21245881 好吧.最终要跑起来了. 要实现跑酷须要用到帧动画,什么是帧动画,不 ...