首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ElasticSearch和jdbc -映射、分析器、过滤器设置

ElasticSearch和jdbc -映射、分析器、过滤器设置
EN

Stack Overflow用户
提问于 2015-09-08 08:35:30
回答 1查看 246关注 0票数 0

我搜索了很多堆叠溢出的问题,ElasticSearch文档,论坛,但都失败了。

我尝试设置ElasticSearch JDBC数据库,并将word搜索的一部分实现到我的搜索中(例如,当您输入'bicycl‘脚本必须搜索自行车时)。我试着用nGram,但我做错了.我所需要的只是在string字段上实现nGram。

下面是我的主要sql配置:

代码语言:javascript
运行
复制
curl -XPUT 'localhost:9200/_river/query_1/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
    "url" : "jdbc:mysql://localhost:3306/testowa",
    "user" : "root",
    "password" : "****",
    "sql" : "SELECT p.products_id as _id, p.products_id, tr.tax_class_id, m.manufacturers_id, p.products_status, products_temporarily_unavailable, ptc.categories_id, ctt.categories_disabled, ctt.category_tags, ctt.categories_name, pd.products_name, manufacturers_name, pd.products_description, p.products_model, p.products_code, pd.products_search_tags, pd.products_description_seo_tag FROM products_description pd, products_to_categories ptc, tax_rates tr, manufacturers m, categories_tree_table ctt, products p LEFT JOIN specials ON specials.products_id = p.products_id AND  status = 1 LEFT JOIN products_gratis pg ON pg.ref_products_id = p.products_id WHERE pd.products_id = p.products_id AND ptc.products_id = p.products_id AND p.products_tax_class_id = tr.tax_class_id AND p.manufacturers_id = m.manufacturers_id AND (p.products_status = 1 or products_temporarily_unavailable = 1) AND pd.language_id = 1 AND m.language_id = 1 AND p.products_is_archive = 0 AND ptc.categories_id = ctt.categories_id AND ctt.categories_disabled != 1",
    "poll": "10s",
    "strategy": "simple",
    "schedule" : "0 1-59 0-23 ? * *",
    "autocommit" : true,
    "index" : "searcher",
    "type" : "query_1"
},
"index" : {
  "index" : "searcher",
  "type" : "query_1",
  "settings" : {
      "analysis" : {
          "filter" : {
              "nGram_filter": {
                 "type": "nGram",
                 "min_gram": 2,
                 "max_gram": 20,
                 "token_chars": [
                    "letter",
                    "digit",
                    "punctuation",
                    "symbol"
                 ]
              }
          },
          "analyzer" : {
              "nGram_analyzer": {
                 "type": "custom",
                 "tokenizer": "my_ngram_tokenizer",
                 "filter": [
                    "lowercase",
                    "asciifolding",
                    "nGram_filter"
                 ]
              },
              "my_search_analyzer" : {
                  "type" : "custom",
                  "tokenizer" : "standard",
                  "filter" : ["standard", "lowercase", "nGram"]
              }
          },
          "tokenizer" : {
              "my_ngram_tokenizer" : {
                  "type" : "nGram",
                  "min_gram" : "3",
                  "max_gram" : "20",
                  "token_chars": [ "letter", "digit" ]
              }
          }
      }
  }


},
"type_mapping" : {
    "searcher" : {
      "query_1" : {
          "_all" : {
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          },
          "products_name" : {
              "type" : "string",
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          },
          "categories_name" : {
              "type" : "string",
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          },
          "manufacturers_name" : {
              "type" : "string",
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          },
          "products_description" : {
              "type" : "string",
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          },
          "products_code" : {
              "type" : "string",
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          },
          "products_model" : {
              "type" : "string",
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          },
          "products_search_tags" : {
              "type" : "string",
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          },
          "products_description_seo_tag" : {
              "type" : "string",
              "analyzer" : "polish",
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "my_search_analyzer"
          }
      }

    }

}

}‘

我做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-09 03:05:03

错误的第一件事是您的JDBC河流规范。indextype_mapping需要进入jdbc结构,而不是在其外部(+类型映射在_all字段之后遗漏了一个properties关键字),因此,一旦您纠正了这一点,就会产生类似的结果:

代码语言:javascript
运行
复制
curl -XPUT 'localhost:9200/_river/query_1/_meta' -d '{
  "type": "jdbc",
  "jdbc": {
    "url": "jdbc:mysql://localhost:3306/testowa",
    "user": "root",
    "password": "****",
    "sql": "SELECT p.products_id as _id, p.products_id, tr.tax_class_id, m.manufacturers_id, p.products_status, products_temporarily_unavailable, ptc.categories_id, ctt.categories_disabled, ctt.category_tags, ctt.categories_name, pd.products_name, manufacturers_name, pd.products_description, p.products_model, p.products_code, pd.products_search_tags, pd.products_description_seo_tag FROM products_description pd, products_to_categories ptc, tax_rates tr, manufacturers m, categories_tree_table ctt, products p LEFT JOIN specials ON specials.products_id = p.products_id AND  status = 1 LEFT JOIN products_gratis pg ON pg.ref_products_id = p.products_id WHERE pd.products_id = p.products_id AND ptc.products_id = p.products_id AND p.products_tax_class_id = tr.tax_class_id AND p.manufacturers_id = m.manufacturers_id AND (p.products_status = 1 or products_temporarily_unavailable = 1) AND pd.language_id = 1 AND m.language_id = 1 AND p.products_is_archive = 0 AND ptc.categories_id = ctt.categories_id AND ctt.categories_disabled != 1",
    "poll": "10s",
    "strategy": "simple",
    "schedule": "0 1-59 0-23 ? * *",
    "autocommit": true,
    "index": "searcher",
    "index_settings": {                 <-- index settings, analyzers go here
      "analysis": {
        "filter": {
          "nGram_filter": {
            "type": "nGram",
            "min_gram": 2,
            "max_gram": 20,
            "token_chars": [
              "letter",
              "digit",
              "punctuation",
              "symbol"
            ]
          }
        },
        "analyzer": {
          "nGram_analyzer": {
            "type": "custom",
            "tokenizer": "my_ngram_tokenizer",
            "filter": [
              "lowercase",
              "asciifolding",
              "nGram_filter"
            ]
          },
          "my_search_analyzer": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": [
              "standard",
              "lowercase",
              "nGram"
            ]
          }
        },
        "tokenizer": {
          "my_ngram_tokenizer": {
            "type": "nGram",
            "min_gram": "3",
            "max_gram": "20",
            "token_chars": [
              "letter",
              "digit"
            ]
          }
        }
      }
    },
    "type": "query_1",
    "type_mapping": {           <--- your type mapping goes here
      "query_1": {
        "_all": {
          "analyzer": "polish",
          "index_analyzer": "nGram_analyzer",
          "search_analyzer": "my_search_analyzer"
        },
        "properties": {
          "products_name": {
            "type": "string",
            "analyzer": "polish",
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "my_search_analyzer"
          },
          "categories_name": {
            "type": "string",
            "analyzer": "polish",
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "my_search_analyzer"
          },
          "manufacturers_name": {
            "type": "string",
            "analyzer": "polish",
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "my_search_analyzer"
          },
          "products_description": {
            "type": "string",
            "analyzer": "polish",
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "my_search_analyzer"
          },
          "products_code": {
            "type": "string",
            "analyzer": "polish",
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "my_search_analyzer"
          },
          "products_model": {
            "type": "string",
            "analyzer": "polish",
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "my_search_analyzer"
          },
          "products_search_tags": {
            "type": "string",
            "analyzer": "polish",
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "my_search_analyzer"
          },
          "products_description_seo_tag": {
            "type": "string",
            "analyzer": "polish",
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "my_search_analyzer"
          }
        }
      }
    }
  }
}'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32452979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档