I’m sure this is somehow a duplicate. But every solution I found didn’t help me out. To make things simple I post very minimal examples of my data.
What I want to achieve is to add a mapping for nested form objects and to define an analyzer for sorting the text properties of these objects. I also found examples with _doc keys. But I don’t understand why I should use them.
{
"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'
Result
{"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}
EDIT
I changed my data according to the answer I got from ESCoder. It doesn’t seem to work.
The health of my index is yellow. I don’t know why.
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
The contents of the index look incorrect, too. Lots of nested 'properties' keys.
{
"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" : {
...
EDIT2
Index definition
{
"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
{
"query": {
"nested": {
"path": "article.form",
"query": {
"match": {
"article.form.text": "foo"
}
}
}
}
}
To delete articles
curl -X POST -H 'Content-Type: application/json' "http://localhost:9200/test/_delete_by_query" -d'
{
"query":{
"match_all":{}
}
}'
To delete the index
curl -X DELETE 'http://localhost:9200/test'
I don’t know how to force a re-index, yet.
Contents of the index
$ 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"
}
}
}
}
}