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. 两道不错的递推dp

    hdoj-4055 #include <cstdio> #include <cstring> #include <iostream> #include <al ...

  2. Java依赖注入方式

    pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...

  3. zabbix怎么把英文界面换成中文

    虽然能勉勉强强能看懂大部分英文,但感觉还是直接换中文方便上手一点

  4. MySQL--批量KILL连接

    ============================================== 使用SELECT INTO OUTFILE方式获取到要删除的连接ID并保存为文件,在通过SOURCE执行 ...

  5. cookie和session机制

    一.cookie和session机制之间的差别和联系 1.cookie机制 Cookie意为"甜饼",是由W3C组织提出,最早由Netscape社区发展的一种机制. 眼下Cooki ...

  6. C# to IL 1 Introduction to Microsoft’s IL(MSIL 介绍)

    The code that we write in a programming language like C#, ASP+ or in any other .NETcompatible langua ...

  7. Unity 3D UI Essentials 学习

    Chapter 1: Looking Back,LookingForward Chapter 2: Building Layouts Chapter 3: Control, Control, You ...

  8. 数据驱动 vs 关键字驱动:对搭建UI自动化测试框架的探索

    UI自动化测试用例剖析 让我们先从分析一端自动化测试案例的代码开始我们的旅程.以下是我之前写的一个自动化测试的小Demo.这个Demo基于Selenium与Java.由于现在Selenium在自动化测 ...

  9. MT7628如何配置使用 Openwrt路由模式 (校园网配置)

    1.设置wan,把网线插入wan口 1) 在 MT7628 开发板上的 3 个网口默认都是“LAN 口”功能,但拨号上网一般需要用到“WAN口”的功能,所以我们需要将其中一个切换为“WAN 口”,这里 ...

  10. java对文件操作之实用

    创建文件 package com.pre; import java.io.File; public class WJ { public static void main(String[] args) ...