2

是否可以仅索引对象的某些部分elasticsearch

例子:

$ curl -XPUT 'http://localhost:9200/test/item/1' -d '
{
    "record": {
        "city": "London",
        "contact": "Some person name"
    }
}

$ curl -XPUT 'http://localhost:9200/test/item/2' -d '
{
    "record": {
        "city": "London",
        "contact": { "phone": "some-phone-number", "name": "Other person's name" }
    }
}

$ curl -XPUT 'http://localhost:9200/test/item/3' -d '
{
    "record": {
        "city": "Oslo",
        "headquarters": { "phone": "some-other-phone-number", 
                          "address": "some address" }
    }
}

我只希望城市名称是可搜索的,我希望对象的所有剩余部分都没有索引并且完全任意。例如,某些字段可以将其类型从对象更改为对象。是否可以编写允许这种行为的映射?

更新

我的最终解决方案如下所示:

{
     "test": {
        "dynamic": "false",
        "properties": {
            "name": {
                "type": "string"
            }
        }
    }
}

我在映射的最低级别添加了“动态”:“假”,它按预期工作。

4

1 回答 1

3

您可以通过禁用整个类型或仅内部对象记录的动态映射来实现此目的:

"mappings": {
    "doc": {
        "properties": {
            "record": {
                "type": "object",
                "properties": {
                    "city": {"type": "string"}
                },
                "dynamic": false
            }
        }
    }
}
于 2013-07-11T18:00:28.473 回答