elasticsearch 无法为Elasticsearch 7创建工作索引,elasticsearch,indexing,elasticsearch,Indexing" /> elasticsearch 无法为Elasticsearch 7创建工作索引,elasticsearch,indexing,elasticsearch,Indexing" />

elasticsearch 无法为Elasticsearch 7创建工作索引

elasticsearch 无法为Elasticsearch 7创建工作索引,elasticsearch,indexing,elasticsearch,Indexing,我肯定这是一个复制品。但我找到的每一个解决方案都帮不了我。为了让事情变得简单,我发布了一些非常简单的数据示例 我想要实现的是为嵌套表单对象添加映射,并定义一个分析器来对这些对象的文本属性进行排序。我还找到了带有_doc键的示例。但我不明白我为什么要用它们 { "settings": { "analysis": { "analyzer": { "asciifolding": {

我肯定这是一个复制品。但我找到的每一个解决方案都帮不了我。为了让事情变得简单,我发布了一些非常简单的数据示例

我想要实现的是为嵌套表单对象添加映射,并定义一个分析器来对这些对象的文本属性进行排序。我还找到了带有_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"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
第1.1条 test_index.json test_query.json 结果 编辑 我根据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": [
                "standard",
                "lowercase",
                "asciifolding"
              ]
            }
          }
        }
      },
      "mappings": {
        "properties": { 
          "article": {                     // note this
            "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": {
        "form": [
          {
            "text": "foo",
            "location": "somewhere"
          },
          {
            "text": "bar",
            "location": "somewhere else"
          }
        ]
      }
    }
    
    {
      "query": {
        "nested": {
          "path": "article.form",
          "query": {
            "match": {
              "article.form.text": "foo"   // note this
            }
          }
        }
      }
    }
    
    "hits": [
          {
            "_index": "67111821",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.6931471,
            "_source": {
              "article": {
                "form": [
                  {
                    "text": "foo",
                    "location": "somewhere"
                  },
                  {
                    "text": "bar",
                    "location": "somewhere else"
                  }
                ]
              }
            }
          }
        ]
    
    索引数据:

        {
      "settings": {
        "analysis": {
          "analyzer": {
            "asciifolding": {
              "tokenizer": "standard",
              "filter": [
                "standard",
                "lowercase",
                "asciifolding"
              ]
            }
          }
        }
      },
      "mappings": {
        "properties": { 
          "article": {                     // note this
            "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": {
        "form": [
          {
            "text": "foo",
            "location": "somewhere"
          },
          {
            "text": "bar",
            "location": "somewhere else"
          }
        ]
      }
    }
    
    {
      "query": {
        "nested": {
          "path": "article.form",
          "query": {
            "match": {
              "article.form.text": "foo"   // note this
            }
          }
        }
      }
    }
    
    "hits": [
          {
            "_index": "67111821",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.6931471,
            "_source": {
              "article": {
                "form": [
                  {
                    "text": "foo",
                    "location": "somewhere"
                  },
                  {
                    "text": "bar",
                    "location": "somewhere else"
                  }
                ]
              }
            }
          }
        ]
    
    搜索查询:

        {
      "settings": {
        "analysis": {
          "analyzer": {
            "asciifolding": {
              "tokenizer": "standard",
              "filter": [
                "standard",
                "lowercase",
                "asciifolding"
              ]
            }
          }
        }
      },
      "mappings": {
        "properties": { 
          "article": {                     // note this
            "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": {
        "form": [
          {
            "text": "foo",
            "location": "somewhere"
          },
          {
            "text": "bar",
            "location": "somewhere else"
          }
        ]
      }
    }
    
    {
      "query": {
        "nested": {
          "path": "article.form",
          "query": {
            "match": {
              "article.form.text": "foo"   // note this
            }
          }
        }
      }
    }
    
    "hits": [
          {
            "_index": "67111821",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.6931471,
            "_source": {
              "article": {
                "form": [
                  {
                    "text": "foo",
                    "location": "somewhere"
                  },
                  {
                    "text": "bar",
                    "location": "somewhere else"
                  }
                ]
              }
            }
          }
        ]
    
    搜索结果:

        {
      "settings": {
        "analysis": {
          "analyzer": {
            "asciifolding": {
              "tokenizer": "standard",
              "filter": [
                "standard",
                "lowercase",
                "asciifolding"
              ]
            }
          }
        }
      },
      "mappings": {
        "properties": { 
          "article": {                     // note this
            "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": {
        "form": [
          {
            "text": "foo",
            "location": "somewhere"
          },
          {
            "text": "bar",
            "location": "somewhere else"
          }
        ]
      }
    }
    
    {
      "query": {
        "nested": {
          "path": "article.form",
          "query": {
            "match": {
              "article.form.text": "foo"   // note this
            }
          }
        }
      }
    }
    
    "hits": [
          {
            "_index": "67111821",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.6931471,
            "_source": {
              "article": {
                "form": [
                  {
                    "text": "foo",
                    "location": "somewhere"
                  },
                  {
                    "text": "bar",
                    "location": "somewhere else"
                  }
                ]
              }
            }
          }
        ]
    

    首先,非常感谢@ESCoder

    这是我问题的部分答案。我把索引放错了路径。可能是因为我不允许在某个时候覆盖已经存在的索引。后来我学习了如何删除索引。我删除了排序字段的定义,因为它也不起作用,我得到了另一条很好的错误消息

    错误:/test/文章 正确:/test 新问题 识别索引中的嵌套对象定义。但现在数据库认为我的数据实际上没有嵌套对象

    测试数据 错误消息 编辑 现在我知道了。出了什么问题。我必须把我的测试文章放入/test/\u doc/任何东西

    错误的 对的
    现在,一个非常简单的索引就可以工作了。

    谢谢您的帮助。我更改了映射和搜索查询。我仍然得到相同的结果:“未能创建查询:[嵌套]路径[article.form]下的嵌套对象不是嵌套类型”。这是我以前尝试过的众多变体之一。我不知道还会出什么问题。如何将每个文档加载到Elasticsearch中,以及加载到哪个路径?也许问题就在那里。请看原始问题的底部。我删除了索引和文档,并多次重新创建它们。同样的结果。我不知道你怎么可能得到一个合适的结果。而且索引的内容看起来也不正确。我将用更多信息编辑我的问题。@MarcusHusar您使用的是哪个版本的ES?您是否遵循以下操作:删除索引-->使用新索引映射创建索引-->索引数据-->搜索查询?@MarcusHusar您可以分享您现在使用的确切索引映射吗?我将以EDIT2的形式将新数据添加到我的问题中。
    {
      "article": {
        "form": [
          {
            "text": "foo",
            "location": "somewhere"
          },
          {
            "text": "bar",
            "location": "somewhere else"
          }
        ]
      }
    }
    
    {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"cannot change object mapping from nested to non-nested"}],"type":"illegal_argument_exception","reason":"cannot change object mapping from nested to non-nested"},"status":400}
    
    url -X PUT -H 'Content-Type: application/json' -T test_article.json 'http://localhost:9200/test/article/1'
    
    url -X PUT -H 'Content-Type: application/json' -T test_article.json 'http://localhost:9200/test/_doc/1'