【发布时间】:2021-07-10 16:31:35
【问题描述】:
我确定这在某种程度上是重复的。但是我找到的每一个解决方案都没有帮助我。为了简单起见,我发布了非常少的数据示例。
我想要实现的是为嵌套表单对象添加一个映射和来定义一个分析器来对这些对象的文本属性进行排序。我还找到了带有 _doc 键的示例。但我不明白为什么要使用它们。
{
"settings": {
"analysis": {
"analyzer": {
"asciifolding": {
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"properties": {
"article": {
"properties": {
"form": {
"type": "nested",
"properties": {
"text": {
"type": "text",
"analyzer": "asciifolding",
"fields": {
"sort": {
"type": "icu_collation_keyword",
"index": false,
"language": "it",
"country": "IT",
"variant": "@collation=standard"
}
}
}
}
}
}
}
}
}
}
article_1.json
{
"article": {
"form": [
{
"text": "foo",
"location": "somewhere"
},
{
"text": "bar",
"location": "somewhere else"
}
]
}
}
test_index.json
{
"settings": {
"index.mapping.single_type": true,
"analysis": {
"analyzer": {
"asciifolding": {
"tokenizer": "standard",
"filter": ["standard", "lowercase", "asciifolding"]
}
}
}
},
"mappings": {
"article": {
"properties": {
"form": {
"type": "nested",
"properties": {
"text": {
"type": "text",
"analyzer": "asciifolding",
"fields": {
"sort": {answer
"type": "icu_collation_keyword",
"index": false,
"language": "it",
"country": "IT",
"variant": "@collation=standard"
}
}
}
}
}
}
}
}
}
test_query.json
{
"query" : {
"nested" : {
"path": "article.form",
"query": {
"match": { "form.text": "foo" }
}
}
}
}
$ curl -X PUT -H 'Content-Type: application/json' -T article_1.json 'http://localhost:9200/test/article/article_1'
$ curl -X PUT -H 'Content-Type: application/json' -T test_index.json 'http://localhost:9200/test/article/'
$ curl -X GET -H 'Content-Type: application/json' -T test_query.json 'http://localhost:9200/test/article/_search'
结果
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: [nested] nested object under path [article.form] is not of nested type","index_uuid":"AOi0L14-Q3mOo2YJqvAnjA","index":"test"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"test","node":"UdlgcachRGih0q4bFwQcNg","reason":{"type":"query_shard_exception","reason":"failewilld to create query: [nested] nested object under path [article.form] is not of nested type","index_uuid":"AOi0L14-Q3mOo2YJqvAnjA","index":"test","caused_by":{"type":"illegal_state_exception","reason":"[nested] nested object under path [article.form] is not of nested type"}}}]},"status":400}
编辑
我根据我从 ESCoder 得到的答案更改了我的数据。它似乎不起作用。
我的索引的健康状况是黄色的。我不知道为什么。
curl 'localhost:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open test 2bwqzUFHSdWerqcMTvekkw 1 1 2 0 15.1kb 15.1kb
索引的内容看起来也不正确。许多嵌套的“属性”键。
{
"test" : {
"aliases" : { },
"mappings" : {
"properties" : {
"article" : {
"properties" : {
"form" : {
"properties" : {
"location" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"text" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
},
"mappings" : {
"properties" : {
"properties" : {
"properties" : {
"article" : {
"properties" : {
"properties" : {
"properties" : {
"form" : {
"properties" : {
"properties" : {
...
编辑2
索引定义
{
"settings": {
"analysis": {
"analyzer": {
"asciifolding": {
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"properties": {
"article": {
"properties": {
"form": {
"type": "nested",
"properties": {
"text": {
"type": "text",
"analyzer": "asciifolding",
"fields": {
"sort": {
"type": "icu_collation_keyword",
"index": false,
"language": "it",
"country": "IT",
"variant": "@collation=standard"
}
}
}
}
}
}
}
}
}
}
查询
{
"query": {
"nested": {
"path": "article.form",
"query": {
"match": {
"article.form.text": "foo"
}
}
}
}
}
删除文章
curl -X POST -H 'Content-Type: application/json' "http://localhost:9200/test/_delete_by_query" -d'
{
"query":{
"match_all":{}
}
}'
删除索引
curl -X DELETE 'http://localhost:9200/test'
我还不知道如何强制重新索引。
索引内容
$ curl -X GET 'http://localhost:9200/test?pretty'
{
"test" : {
"aliases" : { },
"mappings" : {
"properties" : {
"mappings" : {
"properties" : {
"properties" : {
"properties" : {
"article" : {
"properties" : {
"properties" : {
"properties" : {
"form" : {
"properties" : {
"properties" : {
"properties" : {
"text" : {
"properties" : {
"type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
},
"type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"number_of_shards" : "1",
"provided_name" : "test",
"creation_date" : "1618506388668",
"number_of_replicas" : "1",
"uuid" : "1OY-3mJYTOyaIi8cch5cLQ",
"version" : {
"created" : "7120099"
}
}
}
}
}
【问题讨论】: