gpt4 book ai didi

php - 未分析Elasticsearch无法在排序中工作

转载 作者:行者123 更新时间:2023-12-02 23:34:16 25 4
gpt4 key购买 nike

我在elasticsearch中添加了“未分析的映射”选项,对结果进行排序时不起作用,这是我使用http://localhost:9200/_river/jdbc/_search时的映射

 "mappings": {
"jdbc": {
"dynamic_templates": [
{ "notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}

但是,当我对结果进行排序时,它会像
http://localhost:9200/jdbc/_search?pretty=true&sort=field:asc

{
field: "McDermott Will Amery",
},
sort: [
"amery"
]
}

但是我需要从字段中的起始单词开始按A-Z顺序排列结果

更新:元数据中的河流规范
http://localhost:9200/_river/jdbc/_meta

{
"_index": "_river",
"_type": "jdbc",
"_id": "_meta",
"_version": 1,
"found": true,
"_source": {
"type": "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/dbname",
"user": "user",
"password": "pass",
"sql": "SQL QUERY",
"poll": "24h",
"strategy": "simple",
"scale": 0,
"autocommit": true,
"bulk_size": 5000,
"max_bulk_requests": 30,
"bulk_flush_interval": "5s",
"fetchsize": 100,
"max_rows": 149669,
"max_retries": 3,
"max_retries_wait": "10s",
"locale": "in",
"digesting": true
},
"mappings": {
"jdbc": {
"dynamic_templates": [
{
"notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}
}

最佳答案

我认为您的配置对您要执行的操作不正确。让我们重新开始。首先,让我们删除您的_river索引,然后再次从头开始创建它:

curl -XDELETE localhost:9200/_river

现在让我们再次创建它,但是这次使用 correct configuration,即:
  • 您的映射需要在jdbc.type_mapping字段
  • ,您需要指定目标indextype,将数据存储在其中

  • 这是它的样子
    curl -XPUT 'localhost:9200/_river/jdbc/_meta' -d '{
    "type" : "jdbc",
    "jdbc": {
    "driver": "com.mysql.jdbc.Driver",
    "url": "jdbc:mysql://localhost:3306/dbname",
    "user": "user",
    "password": "pass",
    "sql": "SQL QUERY", <-- add your SQL query
    "poll": "24h",
    "strategy": "simple",
    "scale": 0,
    "autocommit": true,
    "bulk_size": 5000,
    "max_bulk_requests": 30,
    "bulk_flush_interval": "5s",
    "fetchsize": 100,
    "max_rows": 149669,
    "max_retries": 3,
    "max_retries_wait": "10s",
    "locale": "in",
    "digesting": true,
    "index": "your_index", <-- add this
    "type": "your_type", <-- add this
    "type_mapping": { <-- add your mapping here
    "your_type": { <-- match this with "type" above
    "dynamic_templates": [{
    "notanalyzed": {
    "match": "*",
    "match_mapping_type": "string",
    "mapping": {
    "type": "string",
    "index": "not_analyzed"
    }
    }
    }]
    }
    }
    }
    }'

    然后,当您的SQL查询运行时,它将数据存储在 your_index索引内,并使用 your_type映射类型。

    最后,您可以使用以下查询搜索数据:
     curl -XGET 'http://localhost:9200/your_index/your_type/_search?pretty=true&sort=field:asc'

    更新

    您还可以使用以下映射定义一个多字段。然后,您就可以在 not_analyzed字段上进行排序,并在 analyzed上进行搜索:
    "dynamic_templates": [{
    "multi": {
    "match": "*",
    "match_mapping_type": "string",
    "mapping": {
    "type": "string",
    "fields": {
    "raw": {
    "type": "string",
    "index": "not_analyzed"
    }
    }
    }
    }
    }]

    在名为 field的字段上的查询将是
    curl -XGET 'http://localhost:9200/your_index/your_type/_search?pretty=true&q=field:Luke&sort=field.raw:asc'

    关于php - 未分析Elasticsearch无法在排序中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33384298/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com