Ich möchte einige Daten von meinem Elasticsearch Server mit Hilfe von „regexpQuery“ lokal bekommen, und dafür habe ich die folgende Methode:Elasticsearch Java API Suche mit regex
public void getProductsStartingWithString() throws ParseException {
Client client = getClient();
SearchResponse response = null;
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
.must(QueryBuilders.regexpQuery("ProductCode", "FA.*"));
if (response == null || response.getHits().hits().length != 0) {
response = client.prepareSearch("warehouse-550")
.setTypes("core2")
.setQuery(boolQuery)
.setSize(100)
.execute()
.actionGet();
}
response.getHits();
}
Die Dokumente in Elasticsearch Aussehen wie folgt:
{
"_index": "warehouse-550",
"_type": "core2",
"_id": "AVOKD0Pq8h4KkDGZwBom",
"_score": null,
"_source": {
"message": "3,550,162.06,FALK0011927540Y,2016-03-16;08:00:00.000\r",
"@version": "1",
"@timestamp": "2016-03-16T07:00:00.000Z",
"path": "D:/Programs/Logstash/x_testingLocally/processed-stocklevels-550-42190516032016.csv",
"host": "EVO385",
"type": "core2",
"Quantity": 3,
"Warehouse": "550",
"Price": 162.06,
"ProductCode": "FALK0011927540Y",
"Timestamp": "2016-03-16;08:00:00.000"
},
"fields": {
"@timestamp": [
1458111600000
]
},
"sort": [
1458111600000
]
}
Aber auf die Antwort bekomme ich immer 0 Treffer.
Die Ausgabe von: curl -XGET "172.22.130.189:9200/warehouse-550/_mapping/core2?pretty"
:
{
"warehouse-550" : {
"mappings" : {
"core2" : {
"properties" : {
"@timestamp" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"@version" : {
"type" : "string"
},
"Price" : {
"type" : "double"
},
"ProductCode" : {
"type" : "string"
},
"Quantity" : {
"type" : "long"
},
"Timestamp" : {
"type" : "string"
},
"Warehouse" : {
"type" : "string"
},
"host" : {
"type" : "string"
},
"message" : {
"type" : "string"
},
"path" : {
"type" : "string"
},
"type" : {
"type" : "string"
}
}
}
}
}
}
Was ich falsch gemacht?
Ist ein Analysator für ProductCode angegeben? Regexp gilt für die Begriffe, die von dem Tokenizer für dieses Feld und nicht für den ursprünglichen Text des Felds erstellt werden. – Rahul
@rahulroc, ich bin ein Anfänger bei der Verwendung von Elasticsearch und Java API dafür. Ich verstehe deine Aussage/Frage nicht. –
Dann müssen Sie https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-analyzers.html lesen. Bitte geben Sie auch die Ausgabe von curl -XGET 'http: // localhost: 9200/warehouse-550/_mapping/core2' – Rahul