【问题标题】:Equivalent of copyField of Solr on ElasticSearch?相当于 ElasticSearch 上 Solr 的 copyField?
【发布时间】:2012-10-18 21:08:58
【问题描述】:

谁能告诉我 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 多值字段时将结果作为单个字段返回。 但它仍然不完全相同,因为它不允许“合并”多个字段。


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

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

ElasticSearch 有解决方案吗?

【问题讨论】:

    标签: elasticsearch search solr lucene elasticsearch-5


    【解决方案1】:

    special _all field 默认获取所有其他字段的副本。您可以使用include_in_all 属性控制包含到_all 字段中。但是,您仅限于这样的一个领域。如果您需要多个字段,则需要在搜索端通过搜索多个字段来处理它。

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

    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"
    

    【讨论】:

    • 我知道_all,但如果需要,最好能够创建许多不同的_all
    • 我同意,这将是一个不错的功能。不幸的是,它还没有实现github.com/elasticsearch/elasticsearch/issues/1169
    • _all 功能已在 Elasticsearch 6+ 中弃用。他们建议使用copy_to 映射参数。
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      相关资源
      最近更新 更多