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的更多相关文章

  1. SpringBoot 2.x 整合ElasticSearch的demo

    SpringBoot 2.x 整合ElasticSearch的demo 1.配置文件application.yml信息 # Tomcat server: tomcat: uri-encoding: U ...

  2. Elasticsearch教程(五) elasticsearch Mapping的创建

    一.Mapping介绍 在Elasticsearch中,Mapping是什么? mapping在Elasticsearch中的作用就是约束. 1.数据类型声明 它类似于静态语言中的数据类型声明,比如声 ...

  3. Elasticsearch mapping映射文件设置没有生效

    Elasticsearch mapping映射文件设置没有生效 问题背景 我们一般会预先创建 Elasticsearch index的 mapping.properties 文件(类似于MySQL中的 ...

  4. elasticsearch mapping问题解决

    1.报错信息如下: [--16T00::,][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch ...

  5. ElasticSearch搜索demo

    ElasticSearch版本:1.4.1 分词:ik jdk:1.7.67 开发工具:Eclipse 系统:win7 忙活了几天,使用ES做成,就是页面有点丑,demo页面如下: 1.搜索主页 2. ...

  6. elasticsearch Mapping 定义索引

    Mapping is the process of defining how a document should be mapped to the Search Engine, including i ...

  7. elasticsearch mapping简单介绍

    这两天一直在看elasticsearch相关的内容,看到mapping这一块,就折腾了下. 一般情况下,我们不需要对elasticsearch的mapping进行设置,但如果希望对索引使用自定义的管理 ...

  8. 如何设计一个高性能 Elasticsearch mapping

    目录 前言 mapping mapping 能做什么 Dynamic mapping dynamic=true dynamic=runtime dynamic=false dynamic=strict ...

  9. Elasticsearch mapping

    //设置mapping Put: http://192.168.1.102:9200/indexName { "settings": { , }, "mappings&q ...

随机推荐

  1. [LeetCode&Python] Problem 389. Find the Difference

    Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...

  2. HDU 1087:Super Jumping! Jumping! Jumping!(LIS)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. django 有关session内部函数做法

    session在set和调用时其实分别做了三步: def fileupload(request): request.session['k1'] = 'ppp' ''' .生成一个随机字符串 .set_ ...

  4. ubuntu shell插件

    1. NetSpeed 在状态栏显示当前网速 2. Screenshot Tool 同样在 Ubuntu 18.04 之前我们使用 Shutter,但在Ubuntu 18.04 Shutter的托盘图 ...

  5. MySQL安装配置错误\日常使用错误

    1.出现报错---应用程序无法正常启动0xc000007b 安装direct 9.0 安装vc++ 2005 安装vc++ 2008 安装vc++ 2012(x64和x86都要装) 安装 .NET4. ...

  6. Eclipse maven 错误修正方法:An error occurred while filtering resources

    最近打开Eclipse后发现项目报红叉,解决办法如下: 1.eclipse中删除该项目(注意:不要删除代码) 2.cmd,进入到项目目录下,执行命令:mvn eclipse:clean 3.重新导入项 ...

  7. MySQL InnoDB Engine--缓冲器数据交换

    通常情况下,缓冲池无法将整个数据库所有数据都进行缓冲,而且不同数据的访问频率不一样,有些数据会被频繁访问,而有些数据可能数月不会被访问一次,因此数据库使用最近最少使用LRU latest Recent ...

  8. day44 数据库学习 索引 引用自egon 老师博客

    MySQL索引管理 总结 #索引是存在硬盘中的, #索引的功能, 1.可以加速查询 2.但是他会降低写入和删除的速度 所以不能乱加索引 总结二 1 最左前缀匹配原则 2设置的索引,它的字段中的内容占空 ...

  9. Gravitee.io docker-compose运行

    Gravitee.io 是一个相对比较完整的api gateway 平台,包含了api 相对比较完整的生命周期管理 同时在访问控制以及日志监控上也做的比较好,是一款可以尝试试用的api gateway ...

  10. openresty 编译ngx_pagespeed 模块-docker 构建

    ngx_pagespeed 是一个很不错的web 优化模块,我们通过简单的配置就可以对于web页面的加载有很大的提升 ngx_pagespeed 依赖psol 模块 Dockerfile   # Do ...