elasticsearch 我在elastisearch中创建了一个多字段,但它';他没有返回任何数据
我已经用这个创建了一个多字段映射elasticsearch 我在elastisearch中创建了一个多字段,但它';他没有返回任何数据,elasticsearch,mapping,field,elasticsearch,Mapping,Field,我已经用这个创建了一个多字段映射 PUT products/product/_mapping { "product": { "properties": { "brand": { "type": "multi_field", "fields": { "brand_original": {"type": "string"}, "raw": {"type" : "string", "index" : "not
PUT products/product/_mapping
{
"product": {
"properties": {
"brand": {
"type": "multi_field",
"fields": {
"brand_original": {"type": "string"},
"raw": {"type" : "string", "index" : "not_analyzed"}
}
}
}
}
}
然后我尝试进行查询,但没有得到任何结果:
GET products/product/_search
{
"_source": [ "brand.raw"],
"query" : {
"match" : {
"brand.raw" : "clinique"
}
}
}
结果是:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
我错过什么了吗?是否可以重新编辑映射?
试试这个:
我创建了如下索引:
DELETE /test_index
PUT /test_index
PUT /test_index/product/_mapping
{
"product": {
"properties": {
"brand": {
"type": "string",
"index": "analyzed",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
并添加了两个文档:
POST /test_index/product/_bulk
{"index":{"_id":1}}
{"brand":"first/brand"}
{"index":{"_id":2}}
{"brand":"second/brand"}
现在,如果我像这样使用“match”
进行查询,我将返回这两个文档
POST /test_index/_search
{
"query": {
"match": {
"brand": "first/brand"
}
}
}
...
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.2712221,
"hits": [
{
"_index": "test_index",
"_type": "product",
"_id": "1",
"_score": 0.2712221,
"_source": {
"brand": "first/brand"
}
},
{
"_index": "test_index",
"_type": "product",
"_id": "2",
"_score": 0.028130025,
"_source": {
"brand": "second/brand"
}
}
]
}
}
但是如果我查询“brand.raw”
,我只会得到完全匹配的文档:
POST /test_index/_search
{
"query": {
"match": {
"brand.raw": "first/brand"
}
}
}
...
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.30685282,
"hits": [
{
"_index": "test_index",
"_type": "product",
"_id": "1",
"_score": 0.30685282,
"_source": {
"brand": "first/brand"
}
}
]
}
}
下面是我用来测试它的代码:
你能发布一些你已经编制索引的示例数据吗?谢谢,很抱歉Google提出了一个愚蠢的问题,它返回了0.9 elasticsearch版本的文档:(我没有意识到。顺便说一句,现在我有很多布兰德的字段,可以删除这些字段,或者我必须重新创建索引。你不能真的删除字段。我的意思是,你可以在没有这些字段的情况下重新编制单个文档的索引,但如果你要对每个文档都这样做,那么重建索引可能同样容易。