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 ...
随机推荐
- HDU - 5201 :The Monkey King (组合数 & 容斥)
As everyone known, The Monkey King is Son Goku. He and his offspring live in Mountain of Flowers and ...
- 20155219 2016-2017-2 《Java程序设计》第6周学习总结
20155219 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 串流设计 1.串流:Java将输入/输出抽象化为串流,数据有来源及目的地,衔接两者的是串流对 ...
- eclipse如何为java项目生成API文档、JavaDoc
当我们的项目很大,编写了很多代码的时候,就需要生成一个标准的API文档,让后续的开发人员,或者合作者可以清晰的了解您方法的使用,那么如何将自己的项目生成API文档呢? 1.点击eclipse的[Pro ...
- inner join 与一般笛卡尔积的区别
inner join 与一般笛卡尔积的区别:inner join是笛卡尔积的特殊形式.如果有表a和表b,表a有m条记录,表b有n条记录,则一般笛卡尔积后得到的记录条数是m*n条,记录之间的组合是随意的 ...
- Atcoder 1973:こだわり者いろはちゃん / Iroha's Obsession
C - こだわり者いろはちゃん / Iroha's Obsession Time limit : 2sec / Memory limit : 256MB Score : 300 points Prob ...
- (10)MySQL触发器(同时操作两张表)
什么是触发器 触发器是与表有关的数据库对象,在满足定义条件时触发,并执行触发器中定义的语句集合.触发器的这种特性可以协助应用在数据库端确保数据的完整性. 举个例子,比如你现在有两个表[用户表]和[日志 ...
- C++学习(十五)(C语言部分)之 数组二
数组大纲 多维数组 二维数组 重点 (三位以上基本不会用到) 都是用来存数据 一个班有20个人 可以用一维数组存20个人的年龄 int age[20]; 一个年级10个班 每个班20人 int age ...
- Python 3 运行 shell 命令
#python 3.5 , win10 引入包 #os.chdir('path') import osimport subprocess #https://docs.python.org/3.5/li ...
- 【liunx】时间处理函数
一.脚本示例 [mylinuxaccount@linux01 ~]$ date +%Y%m%d 20171224 [mylinuxaccount@linux01 ~]$ date +%F 2017-1 ...
- Load Balancing OpenSSH SFTP with HAProxy
In my previous post I described how we setup a Ubuntu Server (12.0.4) as an OpenSSH SFTP server. In ...