美文网首页java学习笔记整理
向文档添加数据并且检索文档数据

向文档添加数据并且检索文档数据

作者: _借东西的小人 | 来源:发表于2019-06-12 19:54 被阅读0次

    添加数据

    请求:PUT 127.0.0.1:9200/books/novel/1(1为id的值)
    插入数据

        {
        "author":"朱林",
        "price":"79.00",
        "num":"1000",
        "publicationdate":"2018-04-01",
        "bookname":"Elasticsearch技术解析与实战",
        "press":"机械工业出版社"
    }
    

    返回值

    {
        "_index": "books",
        "_type": "novel",
        "_id": "1",
        "_version": 1,
        "result": "created",
        "_shards": {
            "total": 2,
            "successful": 2,
            "failed": 0
        },
        "created": true
    }
    

    访问如图所示

    image.png

    检索数据

    请求:GET 127.0.0.1:9200/books/novel/1(1为id的值)
    返回值

    {
        "_index": "books",
        "_type": "novel",
        "_id": "1",
        "_version": 1,
        "found": true,
        "_source": {
            "author": "朱林",
            "price": "79.00",
            "num": "1000",
            "publicationdate": "2018-04-01",
            "bookname": "Elasticsearch技术解析与实战",
            "press": "机械工业出版社"
        }
    }
    

    类型(type)全部检索(条件查询):GET 127.0.0.1:9200/books/novel/_search

    模糊匹配查询

    请求:`GET 127.0.0.1:9200/books/novel/_search
    参数

        {
        "query":{
            "match":{
                "bookname":"价值"
            }
        }
    }
    

    但是这个查询会将会将"价值"分词,所以含"价"和"值"的数据都会被查出来,而我们希望含"价值"这个词语的数据被查询出来,因此用习语匹配查询(短语搜索)

    习语匹配查询(短语搜索)

    请求:`GET 127.0.0.1:9200/books/novel/_search
    参数

        {
        "query":{
            "match_phrase":{
                "bookname":"价值"
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:向文档添加数据并且检索文档数据

        本文链接:https://www.haomeiwen.com/subject/hjwlfctx.html