问题 ElasticSearch上Solr的copyField的等价物?


有人能告诉我ElasticSearch上是否有相同的Solr copyField指令?

我知道有多字段类型: http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html 如果要在同一个字段上应用多个分析器,这很好。

但它并不完全相同。 Solr允许将多个字段“合并”为一个:

<field name="id" type="string" indexed="true" stored="true"/>
<field name="name" type="string" indexed="true" stored="true"/>
<field name="subject" type="string" indexed="true" stored="true"/>
<field name="location" type="string" indexed="true" stored="true"/>
<field name="all" type="text" indexed="true" stored="true" multiValued="true"/>
<copyField source="*" dest="all"/>

这个插件很有前途: https://github.com/yakaz/elasticsearch-analysis-combo

因为它允许在使用ElasticSearch多值字段时将结果作为单个字段返回。 但它仍然不完全相同,因为它不允许“合并”多个字段。


我想要Combo分析器和Solr copyField的组合。

我有一个博客文章模型(标题/描述字段),并希望在单个字段“blogContent”上复制标题和描述,我将在其中应用2个不同的分析器。

ElasticSearch有解决方案吗?


5511
2017-10-29 14:26


起源



答案:


特别 _all 领域  默认情况下,它会获取所有其他字段的副本。你可以控制包含到 _all 现场使用 include_in_all 属性。但是,您只能使用这样的一个字段。如果您需要多个,则需要通过搜索多个字段在搜索端处理它。

通过使用也可以实现类似于copyField的功能 multi_field 随着 "path": "just_name" 属性:

curl -XPUT localhost:9200/test-idx -d '{
    "settings": {
        "index": {
            "number_of_shards": 1,
            "number_of_replicas": 0
        }
    },
    "mappings": {
        "doc": {
            "properties": {
                "first_name": {
                    "type": "multi_field",
                    "path": "just_name",
                    "fields": {
                        "first_name": {"type": "string", "index": "analyzed"},
                        "name": {"type": "string","index": "analyzed"}
                    }
                },
                "last_name": {
                    "type": "multi_field",
                    "path": "just_name",
                    "fields": {
                        "last_name": {"type": "string", "index": "analyzed"},
                        "name": {"type": "string","index": "analyzed"}
                    }
                }
            }
        }
    }
}'
echo
curl -XPUT localhost:9200/test-idx/doc/1 -d '{
    "first_name": "Sebastien",
    "last_name": "Lorber"
}'
echo
curl -XPOST localhost:9200/test-idx/_refresh
echo
curl "localhost:9200/test-idx/doc/_search?q=name:Sebastien"
echo
curl "localhost:9200/test-idx/doc/_search?q=name:Lorber"

8
2017-10-29 14:49



我知道_all但是如果需要的话,能够创建许多不同的_all会更好 - Sebastien Lorber
我同意,这将是一个很好的功能。不幸的是,它还没有实现 github.com/elasticsearch/elasticsearch/issues/1169 - imotov


答案:


特别 _all 领域  默认情况下,它会获取所有其他字段的副本。你可以控制包含到 _all 现场使用 include_in_all 属性。但是,您只能使用这样的一个字段。如果您需要多个,则需要通过搜索多个字段在搜索端处理它。

通过使用也可以实现类似于copyField的功能 multi_field 随着 "path": "just_name" 属性:

curl -XPUT localhost:9200/test-idx -d '{
    "settings": {
        "index": {
            "number_of_shards": 1,
            "number_of_replicas": 0
        }
    },
    "mappings": {
        "doc": {
            "properties": {
                "first_name": {
                    "type": "multi_field",
                    "path": "just_name",
                    "fields": {
                        "first_name": {"type": "string", "index": "analyzed"},
                        "name": {"type": "string","index": "analyzed"}
                    }
                },
                "last_name": {
                    "type": "multi_field",
                    "path": "just_name",
                    "fields": {
                        "last_name": {"type": "string", "index": "analyzed"},
                        "name": {"type": "string","index": "analyzed"}
                    }
                }
            }
        }
    }
}'
echo
curl -XPUT localhost:9200/test-idx/doc/1 -d '{
    "first_name": "Sebastien",
    "last_name": "Lorber"
}'
echo
curl -XPOST localhost:9200/test-idx/_refresh
echo
curl "localhost:9200/test-idx/doc/_search?q=name:Sebastien"
echo
curl "localhost:9200/test-idx/doc/_search?q=name:Lorber"

8
2017-10-29 14:49



我知道_all但是如果需要的话,能够创建许多不同的_all会更好 - Sebastien Lorber
我同意,这将是一个很好的功能。不幸的是,它还没有实现 github.com/elasticsearch/elasticsearch/issues/1169 - imotov


弹性搜索支持copyTo:

您可以在要复制到的字段上添加分析器。


6
2018-03-20 13:35