Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

26.7. Example

26.7.1. 新闻资讯应用案例

			
curl -XDELETE http://localhost:9200/information_v1/news/_mapping?pretty
curl -XDELETE http://localhost:9200/information_v1/?pretty

curl -XPUT http://localhost:9200/information_v1

curl -XPOST http://localhost:9200/information_v1/news/_mapping?pretty -d'
{
    "news": {
            "_all": {
            "analyzer": "ik_max_word",
            "search_analyzer": "ik_max_word",
            "term_vector": "no",
            "store": "false"
        	},
		"properties": {
			"id": { 
				"type": "long"
		    },
			"title": {
                "type": "string",
                "store": "no",
                "term_vector": "with_positions_offsets",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "include_in_all": "true",
                "boost": 8
			},
			"content": {
                "type": "string",
                "store": "no",
                "term_vector": "with_positions_offsets",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "include_in_all": "true",
                "boost": 8
			},
			"tag": {
                "type": "string",
                "store": "no",
                "term_vector": "with_positions_offsets",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "include_in_all": "true",
                "boost": 8
            },
            "ctime": { 
				"type": "date"
		    }
        }
    }
}'

curl -XPOST http://localhost:9200/_aliases -d '
{
    "actions": [
        { "add": {
            "alias": "information",
            "index": "information_v1"
        }}
    ]
}
'

curl -XGET http://localhost:9200/information/?pretty


curl -XPOST 'http://localhost:9200/information/news/1?pretty' -d '{
	"id":1,
	"title":"新闻标题",
	"content":"新闻内容",
	"tag":"新闻标签",
	"ctime":"2011-11-11T11:11:11"
}'

# curl -XGET 'http://localhost:9200/information/news/1?pretty'
{
  "_index" : "information_v1",
  "_type" : "news",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "id" : 1,
    "title" : "新闻标题",
    "content" : "新闻内容",
    "tag" : "新闻标签",
    "ctime" : "2011-11-11T11:11:11"
  }
}

curl -XPOST http://localhost:9200/information/news/_search?pretty  -d'
{
    "query" : { "term" : { "content" : "新闻" }},
    "highlight" : {
        "pre_tags" : ["<b>", "<b>"],
        "post_tags" : ["</b>", "</b>"],
        "fields" : {
            "content" : {}
        }
    }
}'

curl -XPOST http://localhost:9200/information/news/_search  -d'
{
    "query" : { "term" : { "content" : "王宝强" }},
    "highlight" : {
        "pre_tags" : ["<b>", "<b>"],
        "post_tags" : ["</b>", "</b>"],
        "fields" : {
            "content" : {}
        }
    }
}'


curl -XPOST http://localhost:9200/information/news/_search  -d'
{
    "query" : { "term" : { "tag" : "娱乐" }},
    "highlight" : {
        "pre_tags" : ["<b>", "<b>"],
        "post_tags" : ["</b>", "</b>"],
        "fields" : {
            "tag" : {}
        }
    }
}'