Similar problem occurs when I use Java API:
import static
org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.FilterBuilders.;
import java.io.IOException;
import java.util.Date;
import static org.elasticsearch.node.NodeBuilder.;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
public class Test {
public static void main(String[] args) throws ElasticSearchException,
IOException {
Node node = nodeBuilder().local(true).node();
Client client = node.client();
String mapping = jsonBuilder().startObject().startObject("docdate")
.startObject("properties").startObject("mydate").field("type",
"date").string();
client.admin().indices().prepareCreate("ind1").addMapping("docdate",
mapping).execute().actionGet();
client.prepareIndex("ind1", "docdate")
.setSource(jsonBuilder().startObject().field("mydate",
"1000000"))
.setRefresh(true).execute().actionGet();
client.prepareIndex("ind1", "docdate")
.setSource(jsonBuilder().startObject().field("mydate",
"2764800000"))
.setRefresh(true).execute().actionGet();
SearchResponse searchResponse = client.prepareSearch("ind1")
.setSearchType(SearchType.COUNT)
.setFilter(termFilter("mydate", new Date(1000000)))
.execute()
.actionGet();
System.out.println("Hits:"+
searchResponse.getHits().getTotalHits()); //0
searchResponse = client.prepareSearch("ind1")
.setSearchType(SearchType.COUNT)
.setFilter(termFilter("mydate", new Date(2764800000L)))
.execute()
.actionGet();
System.out.println("Hits:"+
searchResponse.getHits().getTotalHits()); //1
node.close();
}
}
The problem occurs when I have to store third-party JSON document on
my database. I expect that by mapping definition I will force Elastic
search to correct value interpretations.
In current case "mydate" is a date and "1000000" should be mapped as
date, but filter [date = new Date(1000000)] fails