Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 如何在elasticsearch_源中存储数据,但不对其进行索引?_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Mapping - Fatal编程技术网 elasticsearch 如何在elasticsearch_源中存储数据,但不对其进行索引?,elasticsearch,mapping,elasticsearch,Mapping" /> elasticsearch 如何在elasticsearch_源中存储数据,但不对其进行索引?,elasticsearch,mapping,elasticsearch,Mapping" />

elasticsearch 如何在elasticsearch_源中存储数据,但不对其进行索引?

elasticsearch 如何在elasticsearch_源中存储数据,但不对其进行索引?,elasticsearch,mapping,elasticsearch,Mapping,我只搜索了几个字段,但我希望能够将整个文档存储在ES中,以避免额外的DB(MySQL)查询 我尝试将index:no,store:no添加到映射中的整个对象/属性,但我仍然不确定字段是否正在被索引,并增加了不必要的开销 假设我有书,每本都有作者。我只想按书名搜索,但我希望能够检索整个文档 这样可以吗: mappings: properties: title: type: string index: analyzed author:

我只搜索了几个字段,但我希望能够将整个文档存储在ES中,以避免额外的DB(MySQL)查询

我尝试将
index:no
store:no
添加到映射中的整个对象/属性,但我仍然不确定字段是否正在被索引,并增加了不必要的开销

假设我有书,每本都有作者。我只想按书名搜索,但我希望能够检索整个文档

这样可以吗:

mappings:
properties:
    title:
        type: string
        index: analyzed
    author:
        type: object
        index: no
        store: no
        properties:
            first_name:
                type: string
            last_name:
                type: string
或者我应该:

mappings:
properties:
    title:
        type: string
        index: analyzed
    author:
        type: object
        properties:
            first_name:
                index: no
                store: no
                type: string
            last_name:
                index: no
                store: no
                type: string
或者我完全错了?
那么不应该索引的
嵌套的
属性呢?

默认情况下,文档的
\u源
将被存储,而不考虑您选择索引的字段。
\u源文件
用于返回搜索结果中的文档,而索引的字段用于搜索

不能在对象上设置
index:no
以阻止对象中的所有字段被索引,但可以使用
path\u match
属性将
index:no
设置应用于对象中的每个字段。下面是一个简单的例子

使用映射创建索引,其中包括
作者
对象和嵌套的
类别
对象的动态模板:

POST /shop
{
    "mappings": {
        "book": {
            "dynamic_templates": [
                {
                    "author_object_template": {
                        "path_match": "author.*",
                        "mapping": {
                            "index": "no"
                        }
                    }
                },
                {
                    "categories_object_template": {
                        "path_match": "categories.*",
                        "mapping": {
                            "index": "no"
                        }
                    }
                }
            ],
            "properties": {
                "categories": {
                    "type": "nested"
                }
            }
        }
    }
}
为文档编制索引:

POST /shop/book/1
{
    "title": "book one",
    "author": {
        "first_name": "jon",
        "last_name": "doe"
    },
    "categories": [
        {
            "cat_id": 1,
            "cat_name": "category one"
        },
        {
            "cat_id": 2,
            "cat_name": "category two"
        }
    ]
}
如果您使用搜索词
book
title
字段中搜索,则会返回文档。如果在
author.first\u name
author.last\u name
上搜索,则不会有匹配项,因为此字段未编制索引:

POST /shop/book/_search
{
    "query": {
        "match": {
            "author.first_name": "jon"
        }
    }
}
对于类别字段上的嵌套查询也是如此:

POST /shop/book/_search
{
    "query": {
        "nested": {
            "path": "categories",
            "query": {
                "match": {
                    "categories.cat_name": "category"
                }
            }
        }
    }
}

您还可以使用该工具期望Lucene索引,并查看哪些字段已被索引

“索引”:“否”
是否意味着
“存储”:“否”
?我读过
store
的意思是在lucene中存储原始属性的
\u源
,但我不确定它与
索引的关系。为了确保-我不必为非索引字段提供映射?如果我放置了一个属性为X且为int的文档,然后放置了一个属性相同但为string的文档,ES不会抛出错误?否,索引的设置不会决定存储的设置。store的默认值是no,这在您的用例中很好,因为启用了_源。如果禁用_源字段并选择要存储的字段,则仅当存在匹配项时,才会在搜索结果中返回存储的字段。您必须为非索引字段提供映射,以便告诉Elasticsearch不要为其编制索引,否则Elasticsearch将使用默认分析器(标准分析器)为字段编制索引。但是,在上述示例中,动态模板用于非索引字段的映射。如果没有字段的映射,则如果更改属性的类型,将不会返回错误。